加载YAML应用程序配置文件的最佳位置在哪里?

pin*_*ngu 4 environment configuration app-config actionmailer ruby-on-rails-3

我安装我的应用程序配置为我的导轨3.1申请中描述这里由Ryan贝茨.

问题是我想在我的环境文件中使用配置为ActionMailer的用户名/密码,但Ryan建议从初始化程序加载配置,它们似乎包含在environment.rb之后.加载配置文件的最佳位置在哪里,以便整个rails应用程序可以访问它?

谢谢

dex*_*ter 6

在这种情况下,此代码应作为预初始化程序进入.从Rails 3开始,所有预初始化代码都需要靠近application.rb的顶部,就在该行之前require 'rails/all'

application.rb中:

require File.expand_path('../boot', __FILE__)  

# load app_config.yml  
require 'yaml'  
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))  

require 'rails/all'
Run Code Online (Sandbox Code Playgroud)