# app/models/concerns/users/csv_conversion.rb class User module CsvConversion extend ActiveSupport::Concern included do def to_csv(options = {}) CSV.generate(options) do |csv| csv << %w[id username email] all.each do |user| csv << [user.id, user.username, user.email] end end end end end end # app/models/user.rb include CsvConversion # Use modules for more complex and widely used logic # Using modules/plugins # in lib/plugins/sponsorable.rb module Sponsorable extend ActiveSupport::Concern module ClassMethods def acts_as_sponsorable(configuration = {}) # Do your logic and define the needed associations ex: product has many sponsors, # A sponsor may sponsor many products , yes a polymorphic association end # If you forgot this line all instances of ActiveRecord::Base will have these methods ! include InstanceMethods end module InstanceMethods def sponsors_count end end end ActiveRecord::Base.send(:include, Sponsorable) # config/initializers/extension.rb require 'sponsorable' # app/models/product.rb acts_as_sponsorable({ max_count: 5, sponsors_type: 'exclusive' }) # Use modules/plugins for shared complex logic and use concerns for model related simple logic