37signals Style
The opinionated layer on top of rails-best-practices-core. Distilled from 37signals codebases (Campfire, Fizzy) and DHH's review patterns. Not everyone writes Rails this way; apply it where the app already does, or where the user asks for it.
Rich Models, No Service Layer
- Domain behavior lives in models. No
app/services/, form objects or decorators. - POROs live in
app/models/: presentation objects (Event::Description), complex operations (SystemCommenter), view-context bundles (User::Filtering). They're model-adjacent, not controller-adjacent. - Slice large models into concerns named for capability (
Closeable,Watchable,Assignable), each self-contained (associations + scopes + methods), ~50-150 lines, cohesive. Prefer nested modules under the model's namespace (Card::Closeableinapp/models/card/closeable.rb) for domain slices; reserveapp/models/concerns/for genuinely cross-model behavior. Never extract concerns containing only private methods. - Association extensions for bulk domain operations: define
grant_to/reviseon thehas_manyproxy; useinsert_allfor bulk creates anddependent: :delete_allon join tables with no callbacks.
State as Records, Not Booleans
Instead of closed: boolean, create a Closure record with creator and timestamps. You get who/when for free, and scoping is trivial:
has_one :closure, dependent: :destroy
scope :closed, -> { joins(:closure) }
scope :open, -> { where.missing(:closure) }
Request Context
- Current attributes (
Current.user,Current.account), with cascading setters (assigningsessionresolvesidentity, which resolvesuserfor the account). - Default values via lambdas:
belongs_to :creator, class_name: "User", default: -> { Current.user };belongs_to :account, default: -> { board.account }. - Human-friendly URLs: override
to_paramwith a per-tenantnumberrather than exposing raw IDs/UUIDs.
Everything Is CRUD
- Turn verbs into nouns. Close →
resource :closure(POST closes, DELETE reopens); publish →resource :publication. No custom member actions. - Singular
resourcefor one-per-parent state;scope module:to group nested controllers (Cards::ClosuresController); shallow nesting for deep hierarchies. - Resource-scoping controller concerns (
CardScopedsets@cardviaCurrent.user.accessible_cards.find_by!(...)) shared across nested controllers, including shared Turbo render helpers. - Same controllers serve HTML/Turbo/JSON via
respond_to; no separate API namespace.
Authorization Without a Library
- No Pundit/CanCanCan: simple predicate methods on models (
card.editable_by?(user),user.can_administer_board?(board)). - Controllers check (
head :forbidden unless ...), models define what the permission means. - Declarative controller macros for auth posture:
allow_unauthenticated_access,ensure_can_administer.
Vanilla Rails Over Gems
Before adding a gem ask: is 50-150 lines in-repo simpler than a dependency? Commonly skipped: Devise, Pundit, ViewComponent, RSpec, FactoryBot, Redis (Solid Queue/Cache/Cable use the DB), service objects, form objects, decorators, GraphQL, SPA frameworks, Tailwind.
Testing in this style: 37signals-testing. Review in DHH's voice: dhh.
Always Flag
- Service objects replacing straightforward model methods.
- Non-RESTful custom actions when resource modeling is clearer.
- Boolean state columns where a record would capture who/when.
- Authorization gems or policy objects where a model predicate would do.
- Private-only concerns: inline them.