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.
Related
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.
rails beginner here
I am trying to set an app to production but having big issues with the asset pipeline. Under development every asset is generated under /assets/blabla.extension
However, I am running nginx and when running rake assets:precompile it creates assets under /public/assets as it should. But when I visit my app it generates urls like /application.css and not /assets/application-digestq12343.css as it should.
I think there is an easy fix to this problem.. but I cannot find it. Please help me!
Update:
From the documentation I read that Sprockets "default" is /assets but it certainly isn't in my application. I use the latest version of rails. Can the documentation be outdated?
http://edgeguides.rubyonrails.org/asset_pipeline.html
Even if I add config.assets.prefix = "/assets" to my production it would still mean that I would not load the assets since the digest would be missing.
I believe this is the same problem I was experiencing. Instead of using url()in your css (or scss), use asset-data-url() and add config.assets.enabled = true to your application config file. Then, rake assets:precompile before you push.
I can't get the foundation-icons to show in production-enviroment (deployment) while in development it works just fine.
When I start the server in production-mode via nginx and the gem puma, basically the only error I get is this:
ActionController::RoutingError (No route matches [GET] "/stylesheets/foundation-icons.css")
I've tried to add this to config/enviroments/production.rb:
config.assets.precompile += %w( vendor/foundation.scss )
and I precompiled using RAILS_ENV=production
I'm using the latest version of foundation:
gem 'foundation-rails', github: 'ahacking/foundation-rails'
Using ruby 2.0.0.p353 and Rails 4.0.2.
Edit:
Foundation-icons has no real relation to the foundation gem. (I wasn't the guy who implemented it in the application)
Edit 2:
Added config.assets.compile = true in config/environments/production.rb witch removed the error, however the icons are still missing.
I found a gem for foundation-icons that works like a charm
https://github.com/zaiste/foundation-icons-sass-rails
I have a rails application that I wanted to upgrade from bootstrap-sass 2 to bootstrap-sass 3
After modifying some css class name, my application worked perfectly on my machine.
I removed the #import bootstrap-responsive ( because bootstrap is natively responsive since 3.0 ) I updated my gemfile and my bundle BUT when I try to deploy my application on Heroku I have the following error :
AssetSync: using /tmp/build_68121564-cc6f-46c8-86d7-ad9ccb180ea1/config/initializers/asset_sync.rb
rake aborted!
File to import not found or unreadable: bootstrap-responsive.
Load paths:
Sass::Rails::Importer(/tmp/build_68121564-cc6f-46c8-86d7-ad9ccb180ea1/app/assets/stylesheets/developers.css.sass)
What I tried so far :
Remove gem bootstap-sass from the asset group (didn't work )
I tried the rake tmp:clear command (didn't work either )
Bundle updated and bundle installed everything again ( still not working )
What should I do ?
The problem is clearly due to some temp files but even after cleaning them I can't push my app on heroku.
Solved
I just had a #import bootstrap-responsive in another .css.scss file im my repo.
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!