Rails Concerns
@endtoendpaper
# shared model methods (and callbacks, validates, scopes, associations) - instance and class

module Item  
extend ActiveSupport::Concern
  
  # instance associations, scopes, validations, callbacks, methods, private methods  
  included do    
    belongs_to :user    
    has_many :collaborations, as: :record, dependent: :destroy    
    has_many :collaborators, :through => :collaborations, source: :user
    ...
    validates_presence_of :visibility
    ...
    before_destroy do      
      tags.each do |tag|        
        tag.destroy if tag.should_delete?      
      end    
    end
    
    def owner_handle      
      '@' + owner.username unless owner.nil?    
    end    

    private

    def private_method     
      ...   
     end  
  end

  class_methods do
    def self.search(search)
       ...
    end
  end
end

ruby-on-rails Updated