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

- 来自: BJ

- 详细资料
搜索本博客
我的相册
screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
翻译www.djangobook.com之 ...
上面的代码要改成:from django.db import models ...
-- by linux.sir -
Rails程序开发的最大问题 ...
我觉得SCA才是解决大规模化开发问题的王道,软件是由组件组成的,组件通过接口对外 ...
-- by 紧急下潜 -
准备将www.beyondrails.co ...
大跃进?先考虑自己有没有那么多时间和精力来维护吧,贪大求全不好。
-- by leondu -
Why OO sucks
...OO和数据操作是两个不同的内容..拿来比较干什么? 相辅相成... O ...
-- by seele -
Why OO sucks
haiyan_qi 写道seemoon 写道感觉这个帖子的争论很水,真的,想不到 ...
-- by seemoon






评论排行榜