rails-composer icon indicating copy to clipboard operation
rails-composer copied to clipboard

Heroku Devise precompile assets errors

Open dwmoore opened this issue 11 years ago • 2 comments

When selecting Heroku deployment as an option in addition to Devise as user authentication an error is thrown on precompile due to the environment variable used in config/initializers/devise.rb:13. This value is nil on setup.

deployment  precompiling assets for Heroku
         run    RAILS_ENV=production rake assets:precompile from "."
rake aborted!
TypeError: no implicit conversion of nil into String
/Users/usrname/rails_apps/angular_rails_app/config/initializers/devise.rb:13:in `+'
/Users/usrname/rails_apps/angular_rails_app/config/initializers/devise.rb:13:in `block in <top (required)>'
/Users/usrname/.rvm/gems/ruby-2.1.2@angular_rails_app/gems/devise-3.4.0/lib/devise.rb:293:in `setup'
/Users/usrname/rails_apps/angular_rails_app/config/initializers/devise.rb:3:in `<top (required)>'
...

Next there is an error stating that the Devise secret key must be set.

rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:

  config.secret_key = 'reallylongencryptioncodehere'
...

Now precompile should work.

To fix the first issue, I am thinking something like this in config/initializers/devise.rb:

domain = Rails.application.secrets.domain_name
domain ||= 'example.com'
config.mailer_sender = 'no-reply@' + domain

As for the next issue, I am not sure if the default key can be used and simply uncommented or if a new key is required. If the earlier is possible then the fix seems straight forward. If the later, I would defer to your expertise.

Thanks again for providing this killer resource!

dwmoore avatar Oct 23 '14 19:10 dwmoore

What happens if you choose:

option  Build a starter application?
          1)  Build a RailsApps example application

and then:

 option  Choose a starter application.
          5)  rails-devise

It builds for me without a problem.

I've also built the application using:

option  Build a starter application?
          3)  Custom application (experimental)

The Rails.application.secrets.domain_name variable should be available in the config/secrets.yml file. I wonder if your config/secrets.yml file is missing?

DanielKehoe avatar Oct 23 '14 19:10 DanielKehoe

It fails on the rails-devise test app for me as well. Also, I have the secrets.yml file so that is not the issue. I will add that I had this exact battle on all my composer generated apps when I precompiled for Heroku deployment, I just learned quickly on to kill out that line or set the environment variable on my local machine.

I am hazarding a guess that your build succeeds because you have a local environment variable set for domain_name whereas most other users will not on their first build. It shouldn't matter what domain_name is, just that you have one. That way you don't get nil returned on Rails.application.secrets.domain_name.

Using the nil guard is probably not the best approach to fixing this but it takes care of the problem for those who don't have a domain_name environment variable set up at the time of running rails composer. Once Rails.application.secrets.domain_name actually gets a value, it takes over from the default.

dwmoore avatar Oct 25 '14 13:10 dwmoore