开发者

Rails automatic class loading at custom directory

Rails has a feature where models, controllers, views, libraries, etc. are automatically loaded when they are needed. This is especially helpful in development mode, where they get automatically reloaded as well.

How do I tell Rails to perform automatic loading somewhere it 开发者_开发知识库doesn't expect to load files? Say, I create a folder app/addons or something, and I want it to load classes there in the same way models are loaded. So if I had app/addons/foo.rb, I want to be able to call the class Foo.


In your config/environment.rb add the following line to the Rails::Initializer.run block:

config.load_paths += %W( #{RAILS_ROOT/app/addons} )


In your environment.rb should be line like this :

config.load_paths += %W( #{RAILS_ROOT}/lib/ #{RAILS_ROOT}/app/addons/ )

Just add some another path you need.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜