Rails 4: Devise.secret_key was not set - ruby-on-rails

This seems to be a popular issue, since I found many similar questions on Stack Overflow:
Devise Token Auth error: Devise.secret_key was not set
Devise Secret Key was not set
Mina and Devise.secret_key was not set
However, none of the above seems to help fix my problem.
Here is my situation:
I installed Font Awesome with the font-awesome-rails gem, and it was working locally, but whenever I deployed to Heroku, Font Awesome icons were no longer appearing.
So, I looked for answers to fix this problem, and found out that I needed to run RAILS_ENV=production bundle exec rake assets:precompile to make things work.
However, when I run this command, I get the following error in Terminal:
rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = '—— MY_SECRET_KEY_HERE ———'
Please ensure you restarted your application after installing Devise or setting the key.
As per the solutions offered in the questions mentioned at the beginning of my question, I do haveconfig.secret_key = ENV['DEVISE_SECRET_KEY'] if Rails.env.production? in devise.rb
Also, as recommended here, I did run heroku config:set DEVISE_SECRET_KEY='—— MY_SECRET_KEY_HERE ———' -- app name_of_my_app_here.
Because I was not sure, I also ran heroku config:set DEVISE_SECRET_KEY=—— MY_SECRET_KEY_HERE ——— -- app name_of_my_app_here (without single quotes around my secret key).
But none of these things worked.
I keep getting the same error.
What am I doing wrong?

I found a solution to this problem.
Instead of keeping on struggling with the font-awesome-rails gem, I uninstalled it and replaced it with font-awesome-sass, which is the official Font Awesome gem for rails.
Following the guidelines offered here (section: EASY: SASS Ruby Gem), I then ran bundle and added:
#import "font-awesome-sprockets";
#import "font-awesome";
to my application.scss file.
I also removed the old #import "font-awesome.css"; line from the very same file.
Now, Font Awesome works both locally and on Heroku.

Related

setting up doorkeeper on rails app

I am following the railscast (#353 OAuth with Doorkeeper pro) and am stuck in setting up doorkeeper. Please see below:
In gemfile, I put gem 'doorkeeper' and then run bundle to install it
Next, I run the rails generate doorkeeper:migration, followed by rake db:migrate
I see a couple of rows of 'create_table' and 'add_index' as expected.
Here's the problem:
In my folder 'initializers', there is no doorkeeper.rb file. What did I miss?
Try this before you run doorkeeper:migration
rails generate doorkeeper:install

Heroku asset compile not working with Rails 3.2 application

I feel like I have exhausted my resources trying to figure this out. I have yet to run into this error with a heroku/rails app before and am simply puzzled as to why my js/css isnt being compiled/uploaded to Heroku.
As stated in the heroku docs your options are to:
1. Compiling assets locally.
2. Compiling assets during slug compilation.
I tried the first option: ran RAILS_ENV=production bundle exec rake assets:precompile, added public/assets and saw the "Detected manifest.yml, assuming assets were compiled locally" line when deploying. No CSS.
I tried the second option (clean git checkout before assets:precompile). Added the 'config.assets.initialize_on_precompile = false' line as suggested for rails 3.x apps. And instead of seeing the expected:
Compiled jquery.js
Compiled jquery_ujs.js
Compiled application.js
Compiled application.css
etc etc
I get 'DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!' warnings. yet that folder is completely empty
Looked into this warning with no sign of it being the root cause for this. Feels like I'm going in circles so I am hoping someone has insight. Thanks in advance!
Heroku docs suggests that add 'rails_12factor' gem to gemfile. Precompling assets before pushing to heroku is not required. And you also must use Heroku's cedar stack only.

Rails 3.2 asset compilation issues on Heroku

It seems a lot of people are having similar problems. I consulted this thread, this, and this article, among others. I have found a lot of topics concerning these issues, but the posted solutions have been unable to find a definitive fix. I am currently running rails 3.2.8 with ruby 1.9.2, and Heroku stack cedar.
I am having two major, related issues:
1) My projects are pushing some assets - not all - to heroku.
Per suggestions in other threads, when I place:
config.assets.initialize_on_precompile = false
in my /config/application.rb,
config.serve_static_assets = true
config.assets.precompile += %w( *.js )
in /config/environments/production.rb, and
gem 'rails_12factor', group: :production
in my gemfile, the push will precompile successfully, however the application.js file is empty on Heroku:
2) Precompiling before a push successfully puts JS on Heroku, but it is no longer recognized.
After removing
config.assets.precompile += %w( *.js )
from /config/production.rb, and running
RAILS_ENV=production bundle exec rake assets:precompile
committing and pushing results with index.html.erb not recognizing JS despite application.js present & non-empty as shown below:
I feel as if I have tried all combinations of these solutions to no avail. I have not yet updated the applications to Rails 4, is this a good idea to do at this time?
Any other suggestions where to go from here?
Oddly, in another Rails 3.2 app of mine, I get a similar error only the first time I visit
Once the page loads, simply hitting refresh loads all content and the errors go away. This app has none of the attempted solutions above in its codebase.
I had the same problem, what solved it for me was specifying my ruby version in the gemfile.
ruby '1.9.3'
No answer, but this may help. I precompile using the options below, which means only MD5 versions are created, this helped me fix a few issues.
rake -v --trace assets:precompile:primary RAILS_ENV=production
I also always do this before a precompile:
rake assets:clean
Also, double-check the exact MD5'd name, both in the html and the name of the file in heroku.
Same happened to me. When I updated the Rails version from 3.2.8 to 3.2.11 it Worked!

Cannot make compass work on Heroku

I'm using compass-rails gem in my Rails app. I'm using rails 3.2 and trying to deploy on Heroku cedar stack.
Assets precompilation seemed to pass without any problems.
I keep getting the following error (in the log) when trying to access the site:
ActionView::Template::Error (File to import not found or unreadable: compass.
What am I doing wrong?
I found the problem. Apparently, Heroku must have the following configuration set:
config.assets.initialize_on_precompile = false
I added it and everything works fine now.

Rails precompile - all.js missing

I am new to rails and using version 3.1.0 and trying to deploy to heroku. I have a very simple application that i have managed to get up and running on heroku after working my way through several issues. I used the command
bundle exec rake assets:precompile
to get heroku to load the assets for the application (i read that heroku requires this for version 3.1.0). The problem is that when i try to run the application, the server gives the error
ActionController::RoutingError (No route matches [GET] "/assets/all.js"):
i have all of the required javascript files in public/javscripts but i cannot find any version of all.js in the assets directory. I have included
config.assets.precompile << '*.js'
in config/application.rb but to no avail.
I was wondering if someone could tell me how I get the precompile to create all.js in the assets directory or if I am completely off track here. i was under the impression that the precompile function compiled all of the javascript files into a single optimized file.
Also, if anyone has any good links for a beginner to understand how the precompile functionality works in rails I would be very appreciative.
Thanks in advance.
The best guide is the official rails guide. There is also the Railscast about it.
In a nutshell your Javascript files go in app/assets/javascript from where the precompile task will process them and put then in the public/assets directory. You should not have to change the precompile config option if the follow the defaults. Don't forget to the use the correct helpers to reference your files.
Read the resources above, and if you are converting an existing app watch the Railscast and follow the last section of the guide - these should point you in the right direction.

Resources