原创作者: hideto   阅读:3963次   评论: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 条 请登录后发表评论
2 楼 libiun 2009-05-13 15:51
并行工程环境的面向成本设计

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics