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
发表评论
- 浏览: 682854 次
- 性别:

- 来自: BJ

- 详细资料
搜索本博客
我的相册
screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
Why OO sucks
希望T1大人还是回到正题上,不要继续搅和到诡辩中了。
-- by hax -
Why OO sucks
python 写道貌似又回到当年java vs c的年代。两种方式,不管是OO还 ...
-- by hax -
Why OO sucks
sungine 写道大师们 。。。。停一下!!! 您们觉得 用科学(或数学、诺 ...
-- by hax -
Rails程序开发的最大问题 ...
人总是最重要的,在代码规范问题上尤其是。 Supervisor也许能某种程度上 ...
-- by rubynroll -
Rails程序开发的最大问题 ...
跟rails技术本身关系不太大,我们每个人在使用这个新技术的时候,都会在犯错或个 ...
-- by liusong1111






评论排行榜