What are Rails concerns and when should you use them?

Answer

Rails concerns (ActiveSupport::Concern) are Ruby modules used to share behavior across multiple models or controllers. They provide included (runs when the module is included) and class_methods (adds class-level methods) DSL. Use concerns when: the same behavior appears in 2+ models (e.g., Searchable, Taggable, Auditable concerns). Avoid concerns when the behavior is only needed in one place (use a plain method), when it hides important logic (making code hard to trace), or when a service object or value object would be a cleaner abstraction. Concerns are not a silver bullet — overuse can create an invisible web of included modules.