Rails - why would a model inside RAILS_ROOT/lib not be available in production mode?

后端 未结 2 1617
不知归路
不知归路 2021-01-05 22:22

I have a class located inside RAILS_ROOT/lib folder, which I use in one of my helpers, and it works great in development.

When I switch to production, the applicati

相关标签:
2条回答
  • 2021-01-05 22:47

    When you call SomeHelper::SomeClass, Rails' autoloading mechanism will try to load file at lib/some_helper/some_class.rb

    Rails won't load everything in lib/*, it will only try to load files when ConstMissing occurs.

    0 讨论(0)
  • 2021-01-05 22:58

    You might need to check differences between the configuration settings between development and production environment: config/environments/production.rb and config/environments/development.rb.

    During the Rails initialization routine, load_plugins() is called which loads all plugins in config.plugin_paths. You need to make sure that your folder lib/ is included, like in

    config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]

    In addition to config.plugin_paths, you can also name the plugins that should be loaded in config.plugins. If that variable contains :all then all plugins (found) will be loaded.

    (By the way: configuration settings equal to either environment should go in config/environment.rb. Any differences between enviroments are due to settings in the respective .rb files.)

    0 讨论(0)
提交回复
热议问题