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
class PostsController < ApplicationController
def new
@post = Post.new
end
def create
<%= form_with url: autosave_draft_path,
method: :post,
local: false,
data: {
controller: "autosave",
autosave_target: "form",
class Recipe < ApplicationRecord
has_many :ingredients, inverse_of: :recipe, dependent: :destroy
accepts_nested_attributes_for :ingredients,
allow_destroy: true,
reject_if: :all_blank
<!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)
class Post < ApplicationRecord
# View counter - increments without hitting the database
kredis_counter :view_count, expires_in: 1.day
# Recent viewers list - stores last 10 viewer IDs
kredis_unique_list :recent_viewers, limit: 10
module Idempotency
extend ActiveSupport::Concern
included do
before_action :check_idempotency_key, only: [:create, :update]
after_action :store_idempotent_response, only: [:create, :update]
base_path = Rails.root.join('storage', 'exports').realpath
requested = base_path.join(params[:filename].to_s).cleanpath
unless requested.to_s.start_with?(base_path.to_s) && requested.file?
raise ActionController::RoutingError, 'Not Found'
end
# Simple mixin
module Loggable
def log(message)
puts "[#{Time.now}] #{self.class.name}: #{message}"
end
end
module Api
module V1
class PostsController < ApplicationController
def create
post = current_user.posts.build(post_params)