RameshVel
RameshVel

Reputation: 65877

Where to put the extension methods(loaded only once) in rails application

I have couple of helper methods added to the existing classes, and i want them to be loaded only once. for example i have a except method

class Array
  def except(array)
    self.select do |item|
      array.exclude? item
    end
  end
end

and would like to call it from different views & controllers like this

 a= [1,2,3,4]
 b=a.except [1,3]

Upvotes: 0

Views: 146

Answers (1)

radiospiel
radiospiel

Reputation: 2479

Put it into a file in config/initializers. These are loaded in alphabetic order; so if some other code uses it during initialisation, just use a file like config/initializers/000_important_monkey_patches.rb

Upvotes: 1

Related Questions