I have a Rails application already in production. The guy before set these environment variables:
...
export RACK_ENV=none
export RAILS_ENV=production
...
What does RACK_ENV=none do? I can't find documentation on it anywhere. Do I need to set it in the Rails application or can I just delete that export?
IMHO it's useless.
To find the current environment a Rails app first looks for the RAILS_ENV environment variable, then for RACK_ENV environment variable, then it defaults to 'development'.
If you're using version 1.7 or later of the database_cleaner gem, and your CI server has RACK_ENV set to production like mine did, you'll need to set RACK_ENV to none (or anything other than production) to appease database_cleaner's safeguard that your tests aren't running in production. (Or you could disable the safeguard altogether, but that seems less safe.)
Looking at current rack source, it appears that the only value of RACK_ENV that is meaningful to rack is development, which causes rack to default the host to localhost instead of to 0.0.0.0. So it's foolish to set RACK_ENV to production in the first place, or to check that it's been set to that, but that foolishness has taken root all over.
Related
I have a one codebase multiple websites (for UK, US etc) setup on Heroku with Rails 4. All works, except when I push to Heroku I see this in the terminal:
remote: ###### WARNING:
remote: You are deploying to a non-production environment: "production_uk".
I have these production rails envs:
production
production_uk
production_us
In my gemfile (and also some other files) I have these environments configured so for example I load puma but I was wondering if I should mind this warning? Maybe heroku treats non-production apps with lower priority or something like this?
I even tried to name rack env "production" while keeping rails env "production_uk" but that had no effect.
Thanks in advanceí!
sounds like you are not setting RAILS_ENV to production, heroku I believe warns you if this is not set.
are you using RAILS_ENV to control your country? if so instead use a different variable for that purpose.
It sounds like you are using RAILS_ENV to control which country the server is supporting. This is why heroku is giving you the warning. It expects to see RAILS_ENV='production'.
I would recommend you set up a separate environment variable (i.e. COUNTRY) and use this to control the country specific configuration of your app rather than than RAILS_ENV
I’ve set the environment variable RACK_ENV to staging via heroku_san’s configuration file (as well as manually).
When listing all ENV variables, it shows correctly as being set to "staging". If I check via the console I’m getting a correct result as well.
However, if I log it within my application_controller, it appears to be "production". Any idea why and how to correct this?
RAILS_ENV is set to "production". I’m guessing that this might cause the problem. Can’t these two differ from each other?
Rails looks for RAILS_ENV first, then for RACK_ENV. I guess, Heroku sets RAILS_ENV to production by default and it takes precedence over RACK_ENV. Try to set RAILS_ENV environment variable to "staging" directly.
And if that doesn't work, you should log ENV in your application controller, so that we can see what are all the environment variables from inside.
I'm relatively new to Ruby on Rails and occasionally I find this convention-over-configuration stuff a little confusing as a lot of things seemed to be hidden from the developer, as in this case.
I'm using rails 2.3.8 and when I run my app locally through NetBeans 6.9/Mongrel on my system it runs using the development environment parameters.. when I deploy it to a Fedora box and run it there in Apache HTTPD it automatically runs using the production environment parameters.
How does my app know which environment to use? I haven't changed anything in my app to set the environment.. both versions locally and on my Fedora box are identical. I can't find anywhere in the code where it is setting the environment.. so how is this working?
Thanks.
In httpd.conf file, write the following in VirtualHost:-
## Specify Rails Environment here,
default value is "production"
RailsEnv development
Thanks...
The primary way to specify rails mode is RAILS_ENV environment variable (I assume development is default, when nothing is specified). You can check its value in bash, echo $RAILS_ENV.
You can also modify ENV['RAILS_ENV'] in your config file to change the mode:
ENV['RAILS_ENV'] = 'production'
edit
I've never used rails with apache, but I think passenger mod can also specify this variable somewhere, checking apache configs might help.
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?
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.
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.
I have an action which causes an exception in my staging environment, but instead of sending the notification to hoptoad (which it should, the hoptoad test rake task works...), it shows me the standard rails stacktrace page like it does in development.
My staging environment is essentially a copy of my production environment with the only difference being the rails environment being set through passenger.
What could be the cause of this? Where should I be looking? I haven't confirmed that production does the same thing as we don't yet have a proper production environment set up, but I assume it would also act the same way.
Are you sure that your staging instance is running in the correct environment? Have you tried outputting Rails.env somewhere in your views just to make sure?
I only ask because you mentioned seeing a stack trace page, which shouldn't happen in a production environment unless you're making the requests locally, or you have config.action_controller.consider_all_requests_local set to true in your environment config.