Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails where to put a method to use in all models

Where should I put a method in Rails that will be used by all of my models?

like image 382
JRPete Avatar asked Feb 07 '12 04:02

JRPete


1 Answers

Active record extensions while server starts

# config/initializers/core_extensions.rb
class ActiveRecord::Base
  # write ur common base code here
  def self.per_page
    @@per_page ||= 10
  end

  def self.pagination(options)
    paginate :per_page => options[:per_page] || per_page, :page => options[:page]
  end
end
like image 104
Sandip Ransing Avatar answered Sep 17 '22 12:09

Sandip Ransing