使用 Rails 3.2。我有以下内容:
# application.rb
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))[Rails.env]
# application.yml
development: &non_production_settings
site_url: http://goodboy.com
site_name_lowercase: good boy
site_name_titleize: Good Boy
production:
site_url: http://goodboy.com
site_name_lowercase: good boy
site_name_titleize: Good Boy
首先,我想设置一个站点范围的配置,但它无法找到常量:
site_name_lowercase: good boy
site_name_titleize: Good Boy
development: &non_production_settings
site_url: http://goodboy.development
production:
site_url: http://goodboy.com
其次,我知道这是一个 YAML 文件,但无论如何我可以使用这样的 Rails 方法:
site_name_lowercase: good boy
site_name_titleize: site_name_lowercase.titleize