I have 2 environments, production and staging, and I am using Capistrano with capistrano-ext gem.
When I deploy to staging using Capistrano and restart passenger, I would like the deployed application to run in staging however it runs in the default production
I tried setting:
set :rails_env, "staging"
in my deploy recipe, but this had no effect.
I am aware this can be done by setting a virtual host in Apache, but I am using shared hosting, so don’t have access. My host offers this advice:
add the following to environment.rb: ENV[‘RAILS_ENV’] = ‘staging’
but this doesn’t help me automate the process with Capistrano.
You can use a capistrano hook to create files on the server or symlink them in from e.g.
shared/when deploying.For Rails 2.3:
On your web host, create the file
shared/preinitializer.rb:Then add this to your
Capfile(or possiblyconfig/deploy.rbif you’re using a newer version of capistrano with Rails 2.x:For Rails 3
Due to the changes in Rails 3’s initialization sequence,
config/preinitializer.rbis not loaded until afterconfig/environment.rbis loaded. So for Rails 3, you want to modifyconfig/environment.rbonly on the server. You could do this with a similar setup like Rails 2 above, but using a symlinked copy ofconfig/environment.rb, and adding the step of deleting the existing file before trying to symlink.Another option would be to overwrite the environment.rb on the server from capistrano. In your
config/deploy.rb: