开发者

Where does config.to_prepare should go in Rails 3.1 app?

I'm trying to use a file that is supposed to be reloaded in development all the time and loaded in production once.

I'm trying to use

config.to_prepare do
  require File.expand_path('config/configatron.rb')
end

This allows for reload开发者_JAVA百科ing of my configatron settings in dev. However it's not working. meaning it's only loaded once, not being reloaded on page refreshes. According to documentation it should. Right now I have it in my application.rb - is that the right place ? If yes does anyone what am I doing wrong?

Thank you


I place my to_prepare blocks in initializers.

There is a problem with your code.

From require documentation: http://ruby-doc.org/core-1.9.3/Kernel.html#method-i-require

The absolute path of the loaded file is added to $LOADED_FEATURES ($"). A file will not be loaded again if its path already appears in $". For example, require 'a'; require './a' will not load a.rb again.

Even when your block is called before each environment reload require won't load your configuration.rb file again.

Instead of using to_prepare you can try to rewrite your code using require_dependency How are require, require_dependency and constants reloading related in Rails?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜