Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrect Ruby on Rails 3 replacement for ENV["RAILS_ENV"] ||= 'production'?
    text
    copied!<p>We're doing an upgrade to Ruby on Rails 3 (like half the world right now), and I've been diligently replacing usages of RAILS_ENV, for example </p> <pre><code>RAILS_ENV == 'wibble' # becomes Rails.env.wibble? </code></pre> <p>But I'm not as certain of what to do with:</p> <pre><code>ENV["RAILS_ENV"] ||= 'production' </code></pre> <p>We've got it at the top of a whole bunch of <a href="http://en.wikipedia.org/wiki/Rake_%28software%29" rel="nofollow">Rake</a> tasks and daemons, and the idea is that you can pass <code>RAILS_ENV</code> on the command-line, but it defaults to 'production' if it's not passed.</p> <p>I'm not sure of the new Rails3-appropriate way of doing this. So for now my <code>rails:upgrade:check</code> is complaining mightily of this intrusion of Rails2-ishness...</p> <p>I don't know if:</p> <pre><code>::Rails.env ||= 'production' </code></pre> <p>will work.</p> <p>Does <code>Rails.env</code> exist in a daemon? </p> <p>Does it automagickally get pre-populated with the value of RAILS_ENV passed on the command-line or do we need a new way of invoking the daemons?</p> <p>What is the correct mantra for this?</p> <hr> <p>Update:</p> <p>Looking into the source-code for <code>Rails.env</code>,</p> <pre><code>def env @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV) end </code></pre> <p>we can deduce a number of things.</p> <p>Firstly, it looks like <code>RAILS_ENV</code> does actually still exist - which means it can be set and <code>Rails.env</code> will find it... </p> <p>If Rails is valid in the context of a daemon, then nothing more needs to be done. If not - then I could just not care much and use the old <code>RAILS_ENV</code> as before.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload