Setting the Ruby on Rails application environment using Capistrano on Phusion Passenger

dangerousdave picture dangerousdave · Apr 24, 2011 · Viewed 21.6k times · Source

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.

Answer

Cory picture Cory · Aug 16, 2011

What you are doing when you setting :rails_env, "staging" environment is setting the environment for the migration. In other words, it's a environment that is only set when you're running capistrano. If I understand you correctly, you want to change the environment when running your app, not deploying.

In order to answer your question, I'll need to know how you are launching (starting) your application.

If you're using Phusion Passenger, you'll need to edit your RAILS_ENV for Passenger

Given that you're in a shared environment, you'll probably want to go with the .htaccess route.