How to call modules in lib folder
I'm new to rails just in case the question sounds stupid, I hav开发者_Python百科e a module in my lib folder, but how can I make calls to my module methods in a controller?
In Rails 2.x lib directory was automatically included in the application’s load path. As of Rails 3, this isn't case, but you can edit this in config/application.rb to avoid the "require 'foo'" thing:
config.autoload_paths += %W(#{config.root}/lib)
If you have a class Foo
in a file in your lib
folder, simply use Foo.method
where method
is the (static) method you want to call.
(But don't forget to have require 'foo'
in your controller file.)
精彩评论