ActiveSupport::Concern ( ActiveRecord Utility Module )

Utility Module

Example : encoding or decoding JSON, generate a random number, or encrypt data

module TagLib
extend ActiveSupport::Concern

included do
scope :whatever_scope, lambda{
where(status: 1)
}
end

def name_downcase()
name.downcase
end

module ClassMethods
def find_by_tags()
# ...
end
end

module InstanceMethods
def tags()
# ...
end
end
end

USAGE

class X < ActiveRecord::Base
include TagLib
end

Rails console

X.whatever_scope

ref : http://www.fakingfantastic.com/2010/09/20/concerning-yourself-with-active-support-concern/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s