← ClaudeAtlas

rails-controllerslisted

Use when writing thin controllers with concerns, resource-oriented design, and REST patterns
mickzijdel/rails-toolkit · ★ 0 · AI & Automation · score 70
Install: claude install-skill mickzijdel/rails-toolkit
# Rails Controller Patterns ## Pattern 1: Thin ApplicationController with Concerns The base controller is just a composition of concerns plus a few global settings. All logic lives in the included modules. ```ruby class ApplicationController < ActionController::Base include Authentication include Authorization include BlockSearchEngineIndexing include CurrentRequest, CurrentTimezone, SetPlatform include RequestForgeryProtection include TurboFlash, ViewTransitions etag { "v1" } stale_when_importmap_changes allow_browser versions: :modern end ``` --- ## Pattern 2: Resource Scoping Concerns When multiple controllers load the same parent resource, create a `*Scoped` concern that handles the loading and provides shared helpers: ```ruby # app/controllers/concerns/card_scoped.rb module CardScoped extend ActiveSupport::Concern included do before_action :set_card, :set_board end private def set_card @card = Current.user.accessible_cards.find_by!(number: params[:card_id]) end def set_board @board = @card.board end def render_card_replacement render turbo_stream: turbo_stream.replace( [ @card, :card_container ], partial: "cards/container", method: :morph, locals: { card: @card.reload } ) end end ``` ```ruby class Cards::CommentsController < ApplicationController include CardScoped # sets @card and @board via before_action before_action :set_comment, only: %i[