title: Why does deploy:assets:precompile fail with the error uninitialized constant RAILS_ENV?
body: <p>The deploy (to both staging &amp; production, on the same server) errors out with:</p>
  
  <pre><code>    triggering after callbacks for `deploy:update_code'
    * executing `deploy:assets:precompile'
    * executing "cd /var/www/staging/releases/20130215205558 &amp;&amp; bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile"
      servers: ["domain.com"]
      [domain.com] executing command
      [domain.com] cd /var/www/staging/releases/20130215205558 &amp;&amp; bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile
   ** [out :: domain.com] rake aborted!
   ** [out :: domain.com] uninitialized constant RAILS_ENV
   ** [out :: domain.com] 
   ** [out :: domain.com] Tasks: TOP =&gt; environment
   ** [out :: domain.com] (See full trace by running task with --trace)
      command finished in 22567ms
  *** [deploy:update_code] rolling back
  </code></pre>
  
  <p>This app is running:</p>
  
  <ul>
  <li>Rails 3.1.4</li>
  <li>Ruby 1.9.2-p290</li>
  </ul>
  
  <p>The deploy.rb file contains:</p>
  
  <pre><code>set :stages, %w(staging production)
  require 'capistrano/ext/multistage'
  require "bundler/capistrano"
  set :application, "appname"
  role :app, "domain.com"
  role :web, "domain.com"
  role :db,  "domain.com", :primary =&gt; true
  set :scm, :git
  set :repository, "git@git.git:username/appname.git"
  set :deploy_via, :remote_cache
  set :user, "username"
  set :runner, "username"
  set :use_sudo, false
  set :shared_children, %w(system log pids spree)
  default_run_options[:pty] = true
  default_run_options[:shell] = false
  require './config/boot'
  require 'airbrake/capistrano'
  load 'deploy/assets'
  namespace :deploy do
    task :restart, :roles =&gt; :app do
      run "touch #{current_path}/tmp/restart.txt"
    end
    task :default do
      update
      restart
      cleanup
    end
    task :finalize_update, :except =&gt; { :no_release =&gt; true } do
      run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
      run &lt;&lt;-CMD
        rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids &amp;&amp;
        mkdir -p #{latest_release}/public &amp;&amp;
        mkdir -p #{latest_release}/tmp &amp;&amp;
        ln -s #{shared_path}/log #{latest_release}/log &amp;&amp;
        ln -s #{shared_path}/system #{latest_release}/public/system &amp;&amp;
        ln -s #{shared_path}/spree #{latest_release}/public/spree &amp;&amp;
        ln -s #{shared_path}/pids #{latest_release}/tmp/pids
      CMD
      if fetch(:normalize_asset_timestamps, true)
        stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
        asset_paths = fetch(:public_children, %w(images stylesheets javascripts)).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
        run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env =&gt; { "TZ" =&gt; "UTC" }
      end
    end
    end
  end
  </code></pre>
  
  <p>The Gemfile contains:</p>
  
  <pre><code>source 'http://rubygems.org'
  gem 'rails', '~&gt; 3.1'
  gem 'spree', '~&gt; 0.70.3'
  gem 'tinymce-rails', '3.4.4'
  gem 'honeypot-captcha'
  gem 'spree_static_content', :git =&gt; 'https://github.com/spree/spree_static_content.git', :branch =&gt; '0-70-stable'
  gem 'spree_editor', :git =&gt; 'https://github.com/commonmedia/spree_editor.git', :branch =&gt; 'master'
  gem 'spree_contact_form', :git =&gt; 'git://github.com/commonmedia/spree-contact-form.git', :branch =&gt; 'master'
  gem 'mysql2'
  gem 'airbrake'
  gem 'newrelic_rpm'
  gem 'jquery-rails'
  gem 'capistrano'
  gem 'capistrano-ext'
  group :assets do
    gem 'sass-rails',   '~&gt; 3.1.5'
    gem 'coffee-rails', '~&gt; 3.1.1'
    gem 'uglifier', '&gt;= 1.0.3'
  end
  group :development do
    gem 'highline'
  end
  group :test do
    gem 'turn', '0.8.2', :require =&gt; false
  end
  group :development, :test do
    gem 'itslog'
  end
  group :staging, :production do
    gem 'therubyracer'
  end
  </code></pre>