6

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.

4

3 回答 3

1

https://stackoverflow.com/a/7541958/304690中描述的方法为我解决了这个问题。

于 2012-02-27T00:14:42.027 回答
1

如果您想直接引用管道中的文件,就像您在这里所做的那样,那么您应该将这些文件添加到预编译数组中,以便它们在生产中工作。

这并没有错。

您可以添加一条包罗万象的规则来为供应商/资产进行预编译,但我个人认为最好根据需要添加内容,以便了解应用程序中发生了什么。

于 2012-01-30T06:01:34.523 回答
-3

我遇到了同样的问题。但是,在我修改了 config/environments/production.rb 上的一行代码之后

旧:config.assets.compile = false 到新:config.assets.compile = true

提交 -am "......" git push git push heroku

最后它起作用了

于 2012-02-01T20:27:14.570 回答