2007-12-24
Rails宝典八十五式:YAML配置文件
关键字: rails yaml configuration
我们的程序中可能有一些参数配置,我们可以将这些配置放在外部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
发表评论
- 浏览: 691980 次
- 性别:

- 来自: BJ

- 详细资料
搜索本博客
我的相册
screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
Rails程序开发的最大问题 ...
认真的看了楼上同学们的议论,觉得大家都说得很好,现在公司也在推Agile,在代码 ...
-- by davidgrubby -
Why OO sucks
OO流行,是因为使GUI开发变得简单,人们自然希望把这种成功推广到所有的开发环境 ...
-- by yayv -
Why OO sucks
多研究些问题,少谈些主义java是OO吗?static的存在就有悖OO
-- by jasongreen -
翻译www.djangobook.com之 ...
上面的代码要改成:from django.db import models ...
-- by linux.sir -
Rails程序开发的最大问题 ...
我觉得SCA才是解决大规模化开发问题的王道,软件是由组件组成的,组件通过接口对外 ...
-- by 紧急下潜






评论排行榜