title: Capistrano deployment and devise secret key
body: <p>I'm trying to deploy a Rails 4.2.5 application to a production server using Capistrano 3.4.0. The setup is pretty straightforward, however, on the assets precompile task in capistrano I get the following error:</p>
  <blockquote>
  <p>Devise.secret_key was not set. Please add the following to your Devise initializer:</p>
  <p>config.secret_key = '{some generated secret}'</p>
  <p>Please ensure you restarted your application after installing Devise or setting the key.</p>
  </blockquote>
  <p>After hours and hours of researching, I've simply done the following:</p>
  <pre><code>if Rails.env == 'production'
    config.secret_key = ENV['DEVISE_SECRET_KEY']
  end
  </code></pre>
  <p>Then I SSH into the server and export the variable. However, when I do <code>cap production deploy</code> I still get the error.</p>
  <p>The exact command is:</p>
  <p><code>cd /home/deploy/app/releases/20160402210708 &amp;&amp; ( export RAILS_ENV=&quot;production&quot; ; ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )</code></p>
  <p>I've read all GitHub issues and StackOverflow answers, but none of them seems to fix my issue, including reinstalling the gem. I've also looked into the devise source code, but according to it what I'm doing should work, so I guess the problem is environment (Capistrano) related. Any hints are appreciated.</p>