Using Rails 3.2 and Capistrano 2. I have an app_config.yml
which I load to the app this way:
# config/app_config.yml
global: &GLOBAL
sitename: Shop
# config/application.rb
require File.expand_path('../boot', __FILE__)
APP_CONFIG = YAML.load_file(File.expand_path('../app_config.yml', __FILE__))[Rails.env]
# call using this method
<%= APP_CONFIG["sitename"] %>
I want to load the same app_config.yml
in my deployment scripts in Capistrano, so that I don't have to re-set the variables again:
# config/deploy.rb
require "bundler/capistrano"
require File.expand_path('../boot', __FILE__)
APP_CONFIG = YAML.load_file(File.expand_path('../app_config.yml', __FILE__))[Rails.env]
set :stages, %w(production staging)
And I hope to access the variable using this way too: APP_CONFIG["sitename"]
, but as I run the deployment script, I get this error:
./config/deploy.rb:4:in `load': uninitialized constant Capistrano::Configuration::Rails
(NameError) # points to the APP_CONFIG = YAML.load_file... line
How can I load the app_config.yml
file correctly?
capistrano does not require any rails code.
that's why calling APP_CONFIG = YAML.load_file(File.expand_path('../app_config.yml', __FILE__))[Rails.env]
raises the exception.
you need to replace the Rails.env
with something else that is used in your capistrano deployment. that might be the stage or just "production"
depending on your setup.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.