开发者

How to call modules in lib folder

开发者 https://www.devze.com 2023-02-03 03:32 出处:网络
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 w

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.)

0

精彩评论

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