Rails.application.config.middleware.insert_before 0, Rack::Cors do
# Development CORS - allow any localhost
allow do
origins(
/http:\/\/localhost:\d+/,
/http:\/\/127\.0\.0\.1:\d+/,
class Board < ApplicationRecord
has_many :cards, dependent: :destroy
belongs_to :owner, class_name: "User"
validates :name, presence: true
end
<%= turbo_frame_tag dom_id(contact) do %>
<tr class="contact-row">
<td><%= contact.name %></td>
<td><%= contact.email %></td>
<td><%= contact.role.titleize %></td>
<td class="actions">
# Gemfile
group :development do
gem 'rack-mini-profiler'
gem 'memory_profiler'
gem 'stackprof' # For flamegraphs
gem 'bullet' # N+1 detection
class Import < ApplicationRecord
include ActionView::RecordIdentifier
enum status: { pending: 0, processing: 1, completed: 2, failed: 3 }
has_one_attached :file
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
class Problem
DEFAULT_TYPE = "https://api.example.com/problems/about:blank".freeze
attr_reader :type, :title, :status, :detail, :instance, :extensions
def initialize(status:, title:, detail: nil, type: nil, instance: nil, extensions: {})
require "loofah"
class HtmlSanitizer
ALLOWED_TAGS = %w[p br a strong em ul ol li blockquote code pre h2 h3].freeze
ALLOWED_ATTRS = %w[href title].freeze
SAFE_SCHEMES = %w[http https mailto].freeze
class ExternalApiClient
def fetch_user_data(user_id)
ActiveSupport::Notifications.instrument(
'api.external_service',
service: 'user_service',
operation: 'fetch_user',
class ActivityPanelController < ApplicationController
def show
@project = Project.find(params[:project_id])
@events = @project.events.order(created_at: :desc).limit(50)
latest = @events.maximum(:updated_at)
class Comment < ApplicationRecord
belongs_to :post
belongs_to :author, class_name: 'User'
# Automatically broadcast changes to all subscribers of this post
after_create_commit -> { broadcast_append_to post, target: "comments" }
class UserNotificationJob < ApplicationJob
queue_as :default
# Retry up to 5 times with exponential backoff
retry_on StandardError, wait: :exponentially_longer, attempts: 5