Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - set environment

I have a rails 3 app (which I upgraded). It runs on passenger and nginx but on my production server it also starts with the environment set to 'production'. I know I am missing something really basic, but I just can't figure out where to set the environment instead of in environment.rb.

Thanks for helping!

UPDATE: ok, I learned I can still do that with Rails.env = 'production'.

That seems kind of old school to me. Do you know an elegant way to configure this maybe in the Capfile or sth like that?

like image 482
val_to_many Avatar asked Oct 13 '10 14:10

val_to_many


People also ask

How is Rails ENV set?

The ENV hash in your Rails application is set when your Rails application starts. Rails loads into ENV any environment variables stored in your computer and any other key-value pairs you add using Figaro gem.

What are Rails configurations?

In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file config/application. rb and environment-specific configuration files (such as config/environments/production.

Where is Rails_env defined?

RAILS_ENV is just an environmental variable which is set in the shell or the operating system itself (or when invoking the process). Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs.


2 Answers

Rails 3 is a little bit different than Rails 2.x in that it has a config.ru file, like other Rack applications.

Passenger detects rails as a Rack app, so you'll have to use RackEnv instead of RailsEnv in the vhost. You can set the environment using RackEnv as per the documentation for Passenger/Nginx.

like image 134
Jason stewart Avatar answered Oct 29 '22 14:10

Jason stewart


You can configure a different RAILS_ENV for each app in your vhost for nginx with passenger. I've never used nginx but in apache it's just a RailsEnv=development directive. That way each site just has it set, no worries with configuring a cap task or variable or anything. See the docs. Note that the default is production so this should already be set for you.

like image 33
brad Avatar answered Oct 29 '22 14:10

brad