Rails concerns

Topics: Ruby on Rails

Concerns are Ruby Mixins with added DSL to simplify their use in Ruby on Rails, specifically models based on Rails ActiveRecord.

Reusable concerns vs one-off concerns

Concerns are often presented as the solution to isolate shared logic between models, for example Auditable or Serializable. However, concerns are also useful when they are only used for a single model because they allow to push logic that is only tangentially related but tightly coupled to a model to the periphery. This improves the Code readability of the main model code because less relevant features are implemented elsewhere.

Criticism

Jason Swett discusses common criticisms in When used intelligently, Rails concerns are great.