lib directory is not looked in by default

自闭症网瘾萝莉.ら 提交于 2020-01-05 07:52:32

问题


I following Ryan's subdomain railscast where het creates a Subdomain class used in his routes and places it in the lib directory. Apparantly my rails app isn't looking in the lib dir by default (my app only starts when I move the subdomain.rb file from lib to eg /app/models)

I always thought that the lib dir was included by default in a rails app? How can I best include this directory to make this happen.

Thanks


回答1:


Rails 3 does not autoload it by default (although Rails 2 does). You have to add it to your autoload_paths in application.rb.

module YourRailsApp
  class Application < Rails::Application
    config.autoload_paths += %W(#{Rails.root}/lib)
    #...
  end
end 

For more info on the reason behind this see:

https://rails.lighthouseapp.com/projects/8994/tickets/5218-rails-3-rc-does-not-autoload-from-lib



来源:https://stackoverflow.com/questions/5273419/lib-directory-is-not-looked-in-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!