1

compile fail with rails and omniauth on heroku

remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        NoMethodError: undefined method `[]' for nil:NilClass
remote:        /tmp/build_f21d4b6cc71ba2ef116eca0b20a72d4b/config/initializers/devise.rb:263:in `block in <main>'
remote:        /tmp/build_f21d4b6cc71ba2ef116eca0b20a72d4b/vendor/bundle/ruby/2.7.0/gems/devise-4.7.1/lib/devise.rb:311:in `setup'
remote:        /tmp/build_f21d4b6cc71ba2ef116eca0b20a72d4b/config/initializers/devise.rb:5:in `<main>'

I follow the devise .rb to 263 which is where I add twitter omniauth

config.omniauth :twitter, Rails.application.credentials.twitter[:app_id], Rails.application.credentials.twitter[:app_secret]

I am storing my credentials stored in config/credentials.yml.enc

Joe Bloggos
  • 889
  • 7
  • 24
  • 2
    Have you configured your `RAILS_MASTER_KEY` environment variable in Heroku? You should be able to copy the same key from your local `config/master.key` file. The `master.key` file shouldn't be committed to your repository. – scilence Jun 01 '20 at 05:40
  • @scilence i haven't had an issue with this on other rails projects....i tried setting as per rails credentials:edit --environment production but get the same issue – Joe Bloggos Jun 01 '20 at 06:40
  • ok so i found this article https://www.viget.com/articles/storing-secret-credentials-in-rails-5-2-and-up/ that mentions adding the master key in the heroku app - under settings Config Vars. i did that and it worked – Joe Bloggos Jun 01 '20 at 07:10

1 Answers1

4

The problem was caused by not being able to access the credentials.yml in production. We could access the master key value in production as it is not committed.

I fixed the issue by adding the master.key-value in Heroku, under settings, config vars master key

Joe Bloggos
  • 889
  • 7
  • 24