开发者

Should I put constants for my Rails project in environment.rb?

I want to store a path for a special directory used by my Rails application. Should I store that in environment.rb, or is there another place this is meant to go?

THE_DIRECTORY_PATH = '/path/to/directory'

Let's assume my controllers + models or libraries in /开发者_如何学Pythonlib need access as well.


How about storing it in a YAML configuration file that gets loaded by an initializer? This Railscast has the details.


Use a robust YAML-file approach that allows per-environment settings. Try app_config, which has loads of great features, including referring syntax like AppConfig.the_directory_path.


If controllers need access to it, then a better place would be the ApplicationController.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜