class FeatureFlag < ApplicationRecord
validates :key, presence: true, uniqueness: true
validates :percentage,
numericality: { only_integer: true,
greater_than_or_equal_to: 0,
less_than_or_equal_to: 100 }
class Comment < ApplicationRecord
belongs_to :commentable, polymorphic: true
belongs_to :author, class_name: "User"
scope :visible, -> { where(deleted_at: nil).order(:created_at) }
class Comment < ApplicationRecord
belongs_to :account
belongs_to :author, class_name: "User"
validates :body, presence: true
class ProductsController < ApplicationController
PER_PAGE = 24
def index
@page = [params[:page].to_i, 1].max
@sort = %w[name price recent].include?(params[:sort]) ? params[:sort] : "recent"
class Current < ActiveSupport::CurrentAttributes
attribute :user, :tenant, :request_id, :ip_address
def user_display
user&.email || "system"
end
module Paginatable
extend ActiveSupport::Concern
included do
before_action :set_pagination_params, only: [:index]
end
class CreatePostService
def initialize(author:, params:)
@author = author
@params = params
end
# Gemfile
gem 'graphql'
# Installation
# rails generate graphql:install
class AddStatusToPosts < ActiveRecord::Migration[6.1]
# Use change for automatic rollback
def change
# Add column without default to avoid table lock
add_column :posts, :status, :string
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["source"]
async copy() {
import { StreamActions } from "@hotwired/turbo"
StreamActions.highlight = function () {
const className = this.getAttribute("data-highlight-class") || "flash-highlight"
const duration = parseInt(this.getAttribute("data-highlight-duration"), 10) || 1500
production:
primary:
adapter: postgresql
url: <%= ENV['DATABASE_URL'] %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>
primary_replica: