Ruby Build a Simple Ruby on Rails Application Deploying Deploying Treebook to Heroku

Missing CSS on Heroku Deployment

I've followed along and was able to finally push my app to Heroku and test it out.

http://treebook-seanperryman.herokuapp.com

It seems that it is not loading up the bootstrap CSS. I've double checked with git status, and everything is added and happy. Also, everything looks fine on my GitHub remote for this (http://github.com/sean-perryman/treebook). Any thoughts on resolving this missing CSS issue?

5 Answers

I asked the question over on StackOverflow, and was given the answer. By default, the Rails app is configured to compile your assets (CSS, etc) on the fly. Heroku does not do this, hence the need to precompile your assets before pushing them to the production site. One thing that was overlooked (I think) was to change the config.serve_static_assets setting in the config/environments/production.rb file to true. After doing this, and repushing the files to Heroku, everything started working.

Ref: SO: Pushing RoR app to Heroku, files in /public are missing

Tim Knight
MOD
Tim Knight
Treehouse Moderator 28,101 Points

Sean, make sure you're precompiling your Sass and CSS assets. Heroku won't compile those on-the-fly like it does in your development environment. From the terminal (within your project folder) you'd write:

rake assets:precompile

I hadn't done that, but I went ahead and did and after the push it still seems the same. I am sure I am just missing something simple.

Tim Knight
Tim Knight
Treehouse Moderator 28,101 Points

What's your heroku development address if you don't mind?

Ignore that... noticed it in your first request.

Tim Knight
Tim Knight
Treehouse Moderator 28,101 Points

Your assets are now on Github, just make sure you're pushing to Heroku also...

git push heroku master

I apologize for my ignorance, but wouldn't it be: http://treebook-seanperryman.herokuapp.com ? If not, if you can tell me how I can retrieve it I would be glad to

Tim Knight
Tim Knight
Treehouse Moderator 28,101 Points

You're right. That's it... you just need to push to heroku now that you've pushed to github.

Tried pushing to Heroku again, same situation. Do I need to remove the app from Heroku and re-push it?

Tim Knight
Tim Knight
Treehouse Moderator 28,101 Points

You can try that but it shouldn't be necessary. It's clear that the files are located in your public/assets folder now on Github. Is Heroku giving you an error when you push?

I made a quick change and re-pushed the code to both GitHub and Heroku. Here is the output from the Heroku push:

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.5.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Using json (1.8.1)
       Using rake (10.3.1)
       Using i18n (0.6.9)
       Using minitest (5.3.3)
       Using thread_safe (0.3.3)
       Using builder (3.2.2)
       Using erubis (2.7.0)
       Using rack (1.5.2)
       Using mime-types (1.25.1)
       Using polyglot (0.3.4)
       Using coffee-script-source (1.7.0)
       Using bcrypt (3.1.7)
       Using arel (5.0.1.20140414130214)
       Using execjs (2.0.2)
       Using thor (0.19.1)
       Using orm_adapter (0.5.0)
       Using hike (1.2.3)
       Using pg (0.17.1)
       Using bundler (1.5.2)
       Using multi_json (1.10.0)
       Using sass (3.2.19)
       Using rdoc (4.1.1)
       Using tzinfo (1.1.0)
       Using tilt (1.4.1)
       Using rack-test (0.6.2)
       Using warden (1.2.3)
       Using treetop (1.4.15)
       Using uglifier (2.5.0)
       Using coffee-script (2.2.0)
       Using sdoc (0.4.0)
       Using activesupport (4.1.1)
       Using sprockets (2.11.0)
       Using mail (2.5.4)
       Using actionview (4.1.1)
       Using jbuilder (2.0.7)
       Using activemodel (4.1.1)
       Using actionpack (4.1.1)
       Using activerecord (4.1.1)
       Using actionmailer (4.1.1)
       Using railties (4.1.1)
       Using sprockets-rails (2.1.3)
       Using simple_form (3.0.2)
       Using coffee-rails (4.0.1)
       Using devise (3.2.4)
       Using jquery-rails (3.1.0)
       Using sass-rails (4.0.3)
       Using turbolinks (2.2.2)
       Using rails (4.1.1)
       Your bundle is complete!
       Gems in the groups development and test were not installed.
       It was installed into ./vendor/bundle
       Bundle completed (0.70s)
       Cleaning up the bundler cache.
       Detected manifest file, assuming assets were compiled locally
-----> WARNINGS:
       Include 'rails_12factor' gem to enable all platform features
       See https://devcenter.heroku.com/articles/rails-integration-gems for more information.

       You have not declared a Ruby version in your Gemfile.
       To set your Ruby version add this line to your Gemfile:
       ruby '2.0.0'
       # See https://devcenter.heroku.com/articles/ruby-versions for more information.

       No Procfile detected, using the default web server (webrick)
       https://devcenter.heroku.com/articles/ruby-default-web-server
-----> Discovering process types
       Procfile declares types -> (none)
       Default types for Ruby  -> console, rake, web, worker

-----> Compressing... done, 21.7MB
-----> Launching... done, v9
       http://treebook-seanperryman.herokuapp.com/ deployed to Heroku
Michael Wiss
Michael Wiss
19,233 Points

Have you tried rake assets:precompile and then pushing to heroku again?

Using the Firefox console, it seems to be having issues with loading the CSS and JS files that are labeled

'application-73b133c60d8b44702a1aea753db41f19.css' and 'application-4dc704670cd76f40f1697bd36a2d3c02.js'

Now I see those in my GitHub repo in the public/assets directory, is there a way to push just those files up? Perhaps I will try adding a comment in both of those files, re-committing, and re-pushing and see if that will work.

No luck; still getting a 404 on those two files. Do I perhaps need to set some sort of directory permissions or something on the /public directory? I even tried deleting and recompiling the assets, with no luck.