How to make a global function for rails 3?
Can somebody pls tell me how to make a function accessible to all, regardless if its a controller, model, h开发者_运维技巧elper, or view will call it. Is there a way to do this?
in your config/application.rb:
Dir.glob("./lib/*.{rb}").each { |file| require file } # require each file from lib directory
then just create .rb file with all you need and put it to your /lib directory
精彩评论