CSS loading locally but not in Heroku for a rails app
Solution 1
Run bundle exec rake assets:precompile
on your local code
Commit the changes and deploy to heroku
Solution 2
Had the same exact problem, I don't know if it will help other in the future, but I got this on my "git push heroku master" push:
WARNINGS:
Include "rails_12factor" gem to enable all platform features
Updated my gemfile,
*group :production, :staging do
gem 'pg'
gem 'rails_12factor'
end*
Ran it again, to my delight it installed these:
Installing rails_serve_static_assets (0.0.1)
Installing rails_stdout_logging (0.0.1)
Installing rails_12factor (0.0.2)
Site worked perfect after that. Hope that helps someone, I'm new to all this.
Solution 3
Check that in /config/environments/production.rb you have these set to true
config.cache_classes = true
config.serve_static_assets = true
config.assets.compile = true
config.assets.digest = true
git add, git commit and push to heroku.
Solution 4
If your using sass...before you go through all this other trouble...make sure your not mixing .css and .scss files in your assets folder.
Heroku seems to have some trouble mixing the two when compiling assets. I can't explain why of if its an accurate explanation...but, in my own experience all I had to do to fix this was simply rename any .css files to .scss.
Solution 5
Figured it out after trying about everything stackoverflow could suggest. I simply checked git status, saw I had a bunch of uncommitted files (thought this would have been picked up by git push heroku master), then added, committed and pushed to git. Then I started over, ran bundle install, precompiled assets and deployed to heroku and it is working.
Comments
-
pvskisteak5 almost 2 years
I'm following a rails prelaunch signup tutorial. Bootstrap was working fine deployed on heroku, but then I modified the bootstrap_and_override file to include a logo. When launching a rails server locally and viewing, the style is as I intended with bootstrap and the new header logo appearing.
Like I did before, I ran rake assets:precompile and pushed to git - followed this tutorial http://railsapps.github.com/rails-heroku-tutorial.html which worked before showing the css while on heroku. The html is showing but it looks like css and bootstrap are missing.
Does anyone have any ideas?
-
Alexander Popov over 9 yearsWould please select an answer that best worked for you. Thank you.
-
-
Thanh Nguyen almost 11 yearsSee heroku docs about rails_12factor
-
Marcus over 10 yearsI feel like an idiot, but thanks for the help. solved everything
-
whiteshooz about 10 yearsThis did the trick! Looks like it was miss a few files in public/assets/
-
Marco over 8 yearsThank you! I'm new to rails, and it worked like a charm!
-
supertext almost 8 yearsWorked for me as well! Thanks for posting this quick solution.
-
tomtomtom about 7 yearsI had the issue that .css where not working but i set
config.assets.compile = true
and it worked. By default with rails 5 it was setted tofalse
. -
Chris Scott over 6 yearsI had an issue using padrino where
normalize.min.css
wasn't showing up on heroku. I was linking to it in the html. I ended up renaming tonormalize.min.scss
and importing it in myapplication.scss
file and it magically worked! -
NemyaNation almost 4 yearsthis indirectly helped me out - I tested localhost:3000 on a different browser than chrome (my main development browser) and it turns out it wasn't working in development either and was just being cached by Chrome. (however ctrl+shift+R made no changes for me...)