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

- 来自: BJ

- 详细资料
搜索本博客
我的相册
screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
Why OO sucks
那篇回复感觉言之无物 反驳得无力
-- by blizzard213 -
Rails宝典之第四十八式: ...
"foo".to_ windows下要按2下TAB自动列出 该类型的方法 P ...
-- by gakaki -
Erlang里实现MapReduce
在双核的机器上,在Windows任务管理器里查看CPU使用:1)调用lists: ...
-- by hideto -
Erlang里实现MapReduce
节约一半的时间应该是因为我在双核的机器上做的测试,如果有更多核的机器或者分布计算 ...
-- by hideto -
每天一剂Rails良药之Tagg ...
已经解决了 可能是版本的问题, 这是另一更好的插件 http://softwa ...
-- by vwangzhen






评论排行榜