Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2.1 asset pipeline not processing /vendors/assets/stylesheets?

I'm reading the "Rails Tutorial: Learn Rails 3.2 By Example" book but I have a slight problem at the end of chapter 4.

In the book you download the Blueprint css framework, add it to /vendor/assets/stylesheets and then reference it in layouts/application.html.erb using:

<%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
<%= stylesheet_link_tag 'blueprint/print',  :media => 'print' %>
<!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->

This works fine on my local machine, but when I deploy it to heroku (cedar) using

$ bundle exec rake assets:precompile
$ git push heroku

It gives an error when I view the site:

app[web.1]: Completed 500 Internal Server Error in 71ms
app[web.1]: ActionView::Template::Error (blueprint/screen.css isn't precompiled):
app[web.1]:     4: <%= stylesheet_link_tag 'blueprint/screen', media: 'screen' %>
app[web.1]:     5: <%= stylesheet_link_tag 'blueprint/print',  media: 'print' %>

At the moment the only way I've been able to get it working is to manually tell rails about the blueprint stylesheets by putting this in production.rb

config.assets.precompile += %w( blueprint/screen.css blueprint/print.css blueprint/ie.css )

Am I doing something wrong? Is there a way to get rake assets:precompile to automatically minify/compress all the files in /vendor/assets/ (if there is, is there a downside to doing this)?

Thanks in advance for any advice.

like image 873
Zak123 Avatar asked Jan 29 '12 23:01

Zak123


People also ask

How do you Precompile an asset?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

How does Rails asset pipeline work?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.

How do I add a SCSS file to Rails?

You can just add the import to the application. scss file so it will look like: @import "bootstrap/bootstrap.

What does rake assets Clean do?

The clean it removes the old versions of the precompiled assets while leaving the new assets in place. Show activity on this post. rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.


2 Answers

If you want to reference files in the pipeline directly, as you have here, then it is expected that you will add those files to the precompile array for them to work in production.

There is nothing wrong with this.

You could add a catch-all rule to precompile for vendor/assets, but personally I think it is better to add stuff as you need it so that you know what is going on in your app.

like image 164
Richard Hulse Avatar answered Oct 16 '22 07:10

Richard Hulse


The approach as described at https://stackoverflow.com/a/7541958/304690 worked for me solving this.

like image 44
gliptak Avatar answered Oct 16 '22 06:10

gliptak