开发者

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]


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜