3

I have recently added a project to Heroku. However, none of the .css files or .js files seem to be working.

I am using Twitter's Bootstrap .css and .js files. I have added the files to their respective directories in vendor/assets.

Based on other questions I have seen asked here I upgraded from Bamboo to Cedar on Heroku. I also tried rake assets:precompile RAILS_ENV=production, changing config.assets.enabled = true to config.assets.enabled = false in application.rb, config.assets.compile = false config.assets.compile = true in production.rb, and about as many combinations of the above things as I could think of.

Everything is working fine locally.

(Adding a link to the github in an attempt to provide more information.) https://github.com/moctopus/sixtydays

1 Answer 1

7

By default assets:precompile won't process the css/js files in /vendor/assets. In production.rb you can use config.assets.precompile to get additional css/js files processed by the asset precompile.

For example, if you had your twitter bootstrap css/js files inside /vendor/assets/bootstrap use:

config.assets.precompile += %w[ bootstrap/*.css bootstrap/*.js ]

Then rake assets:precompile will process them and they'll work on heroku.


see: http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

The default matcher for compiling files includes application.js, application.css and all non-JS/CSS files

Sign up to request clarification or add additional context in comments.

6 Comments

I'm still having no luck. I have precompiled the specific files and pushed them. I also did this, "config.assets.initialize_on_precompile to false in config/application.rb"
Here's an example of my full production.rb file: pastebin.com/hVEUvH6G (I'm using the default unchanged application.rb). I have assets in /vendor/assets/blueprint and use config.assets.precompile += %w[ blueprint/*.css ] to add the css in that folder. After running rake assets:precompile they work on heroku cedar. Are your assets actually getting compiled/moved to /public/assets (and commited to version control)?
I just tried a few different things using a default application.rb. I tried config.assets.precompile += %w[ bootstrap.css ], config.assets.precompile += %w[ stylesheets/*.css ], and config.assets.precompile += %w[ *.css ]. I have confirmed that when rake assets:precompile runs the files are being created and moved to public/assets. I have also confirmed they are in source control. Still no luck.
From your github it looks like you're only precompiling the .css so the javascript_include_tag for bootstrap.js will still error. Use this: config.assets.precompile += %w[ bootstrap*.css bootstrap.js ] and then bundle exec rake assets:precompile add/commit/push to heroku. That should work, I just tested the exact same thing, but if it doesn't, could you post the output of $ heroku logs
The assets are actually getting compiled now, so that's an improvement. It looks like the problem now is the URLs aren't generated correctly because you don't have the sprockets framework (which serves the web assets) loaded. In application.rb uncomment require "sprockets/railtie"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.