#85 YAML Configuration File
程序员文章站
2022-06-13 20:37:35
...
Application configuration shouldn't be spread throughout your code base. Instead a much better place to put it is an external YAML file. See how to do that in this episode.
# 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
上一篇: 记一次 FLask + docker +Gunicorn + gevent 部署服务遇见的问题
下一篇: 1.IntelliJ IDEA 2018.2导入项目报 Unable to import maven project: See logs for details
推荐阅读
-
mybatis-generator - this is not a mybatis generator configuration file 错误
-
Could not find a package configuration file provided by "geographic_msgs"
-
Could not find a package configuration file provided by "OMPL"...
-
NFS(Network File System) Configuration
-
Apache 错误:httpd: Could not open configuration file
-
MySQL安装Write configuration file 提示:configuration file template my.ini Error code-1
-
Spring Boot配置 : YAML (简介+语法+配置文件值注入)+报错提示Spring Boot Configuration Annotation Processor not
-
(已解决)宝塔面板SSL失败|无法启动,提示 nginx: configuration file /www/server/nginx/conf/nginx.conf test failed
-
linux中phpMyAdmin错误提示Wrong permissions on configuration file,_PHP教程
-
Configuration File Options