原创作者: hideto
阅读:3985次
评论:2条
更新时间:2011-05-26
我们的程序中可能有一些参数配置,我们可以将这些配置放在外部YAML文件里而不必污染应用程序代码:
# config/initializers/load_config.rb APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV] # application.rb def authenticate if APP_CONFIG['perform_authentication'] authenticate_or_request_with_http_basic do |username, password| username == APP_CONFIG['username'] && password == APP_CONFIG['password'] end end end # config/config.yml development: perform_authentication: false test: perform_authentication: false production: perform_authentication: true username: admin password: secret
2 楼 libiun 2009-05-13 15:51