Hi all,
I just have a question about shared model methods. I have a method that
will be used for quite a few models in my application (once I’ve cleaned
it up a bit). Where can I place shared model methods? I know that
controllers can use helpers or even the application_controller. But,
what do models use for a shared mechanism? Is it config/initialize?
Can someone explain a quick process for it?
Here’s an example of a shared model method that I will be using:
def self.list(search, page, orderby, sortby, numteams, datevar)
datevar = todaysdate if datevar.empty? || datevar.nil? ||
DATE_VALIDATE_REG.match(datevar).nil?
convert_time = datevar.to_time.beginning_of_week
week_start_date = convert_time.to_date.strftime(’%Y-%m-%d’)
named_scope :compiled_on_week, lambda { { :conditions =>
[‘compiled_on >= ? and compiled_on <= ?’, week_start_date, datevar] } }
orderby = “rank” if orderby.nil? || orderby.empty?
orderall = (sortby != ‘asc’ && sortby != nil) ? “DESC” : “ASC”
compiled_on_week.paginate :joins => :team, :conditions => [‘name
like ?’, “%#{search}%”], :order => orderby + " #{orderall}", :per_page
=> numteams, :page => page
end