module CollectionCacheKey
extend ActiveSupport::Concern
def cache_key_for(scope)
relation = scope.respond_to?(:all) ? scope.all : scope
model = relation.klass
class User < ApplicationRecord
has_many :posts, foreign_key: :author_id, dependent: :destroy
before_validation :normalize_email
before_create :generate_auth_token
after_create :send_welcome_email
class ApplicationController < ActionController::Base
layout -> { turbo_frame_request? ? false : 'application' }
end
class AddUniqueIndexToTags < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def up
execute <<~SQL
UPDATE tags SET name = LOWER(TRIM(name)) WHERE name IS NOT NULL;
class Api::BaseController < ActionController::API
rescue_from Devise::MissingWarden do
head :unauthorized
end
end
class ExplainAnalyzer
def initialize(relation, watched_tables:)
@relation = relation
@watched_tables = Array(watched_tables).map(&:to_s)
end
class NotificationsController < ApplicationController
def mark_all_read
current_member.notifications.unread.update_all(read_at: Time.current)
streams = Turbo::Streams::TagBuilder.new(view_context)
Rails.application.configure do
# Bullet configuration
config.after_initialize do
Bullet.enable = true
Bullet.alert = true # Show JavaScript alert
Bullet.bullet_logger = true # Log to bullet.log
class UserRegistrationForm
include ActiveModel::Model
include ActiveModel::Attributes
attribute :email, :string
attribute :name, :string
<%= form_with model: @post, url: preview_posts_path, data: { turbo_frame: 'preview' } do |f| %>
<%= f.text_area :body, rows: 10, class: 'w-full rounded border p-2' %>
<%= f.submit 'Preview', class: 'mt-2 rounded bg-gray-100 px-3 py-1' %>
<% end %>
<%= turbo_frame_tag 'preview' do %>
<!DOCTYPE html>
<html>
<head>
<title>Contacts</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
module RetryableTransaction
module_function
RETRIABLE = [ActiveRecord::Deadlocked, ActiveRecord::LockWaitTimeout].freeze
def run(max_retries: 3, base_delay: 0.05, &block)