I've been following along Michael Hartl's excellent RoR Tutorial, but I'm using RoR 3.1. I am a newbie to RoR 3.1 and need help related to assets pipeline. Here is my problem:
我一直在学习Michael Hartl出色的RoR教程,但我使用的是RoR 3.1。我是RoR 3.1的新手,需要与资产管道相关的帮助。这是我的问题:
Before continuing to section 5.3, I thought I'd like to push to Heroku and see how things develop. To my surprise "GET /" results in error 500. Everything went OK in my local-development-environment. I then tried running my local sample_app under production-environment (rails s -e production
). Same result, error 500:
在继续讲5.3节之前,我想先介绍一下Heroku,看看情况如何发展。令我惊讶的是,“GET /”会导致错误500。在我的本地开发环境中一切正常。然后,我尝试在生产环境下运行我的本地sample_app (rails s -e生产)。相同的结果,错误500:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Pages#home
Showing /Users/john/Projects/sample_app/app/views/layouts/_stylesheets.html.erb where line #4 raised:
blueprint/screen.css isn't precompiled
Supporting info:
支持信息:
- I put blueprint CSS directory under vendor/assets/stylesheets.
- 我把blueprint CSS目录放在供应商/资产/样式表下。
-
I followed Michael's section 13.1.4 advice and have the following as my app/views/layouts/application.html.erb:
我遵循了Michael的第13.1.4节建议,并将以下内容作为我的应用/视图/布局/应用程序。
<!DOCTYPE html> <html> <head> <title><%= title %></title> <%= render 'layouts/stylesheets' %> <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> </head> <body> <div class="container"> <%= render 'layouts/header' %> <section class="round"> <%= yield %> </section> <%= render 'layouts/footer' %> </div> </body> </html>
-
Content of app/views/layouts/_stylesheets.html.erb:
内容的应用程序/视图/布局/ _stylesheets.html.erb:
<!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %> <%= stylesheet_link_tag 'blueprint/print', :media => 'print' %> <!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
-
I have run bundle exec rake assets:precompile.
我运行了bundle exec rake资产:预编译。
-
Content of public/assets/manifest.yml:
内容的公共/资产/ manifest.yml:
--- logo.png: logo-8e0a5ad292fbb13a2b07e68fa3995406.png rails.png: rails-bd9ad5a560b5a3a7be0808c5cd76a798.png blueprint/plugins/buttons/icons/cross.png: blueprint/plugins/buttons/icons/cross-2ebcd25368006d1b7b0c5b7d6b523ab3.png blueprint/plugins/buttons/icons/key.png: blueprint/plugins/buttons/icons/key-55237526967cbcab3e8cfb12f0029d88.png blueprint/plugins/buttons/icons/tick.png: blueprint/plugins/buttons/icons/tick-3f5fc1f52b505b93f88263e0432d25ce.png blueprint/plugins/buttons/readme.txt: blueprint/plugins/buttons/readme-3ff7f5dbb0288d71f70682fdbe9d86ec.txt blueprint/plugins/fancy-type/readme.txt: blueprint/plugins/fancy-type/readme-e7ed185d1a9f23256d418ab929b464d9.txt blueprint/plugins/link-icons/icons/doc.png: blueprint/plugins/link-icons/icons/doc-b071fd74b88ff38cda8360a53f493013.png blueprint/plugins/link-icons/icons/email.png: blueprint/plugins/link-icons/icons/email-28104e72b3418737d4b9b329c12ec358.png blueprint/plugins/link-icons/icons/external.png: blueprint/plugins/link-icons/icons/external-ee6d976ddb80125fafe1a33c6f8aed10.png blueprint/plugins/link-icons/icons/feed.png: blueprint/plugins/link-icons/icons/feed-59bc8604661681639d25cb7015a32c38.png blueprint/plugins/link-icons/icons/im.png: blueprint/plugins/link-icons/icons/im-afeeb6e0b652c1edb1441bf0fb428596.png blueprint/plugins/link-icons/icons/lock.png: blueprint/plugins/link-icons/icons/lock-d73c4b3b57ce72cb6dbd8b265507ff75.png blueprint/plugins/link-icons/icons/pdf.png: blueprint/plugins/link-icons/icons/pdf-c4c543e5103a8516839a7846b91e1ac4.png blueprint/plugins/link-icons/icons/visited.png: blueprint/plugins/link-icons/icons/visited-fb2370448bc4ea5d079e963a8c0d900b.png blueprint/plugins/link-icons/icons/xls.png: blueprint/plugins/link-icons/icons/xls-5399729cd31dffc492a04b3805cd0be1.png blueprint/plugins/link-icons/readme.txt: blueprint/plugins/link-icons/readme-42c02030199cd36a671d4b623cb4dc36.txt blueprint/plugins/rtl/readme.txt: blueprint/plugins/rtl/readme-8d11bf76e19fb3fc7dbc6c2ddb54b92d.txt blueprint/src/grid.png: blueprint/src/grid-973add038ed86febca85f03e8b35b94a.png jquery-ui.min.js: jquery-ui-7e33882a28fc84ad0e0e47e46cbf901c.min.js jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js application.js: application-a552e1db33b8be6a42eedf1261916f3c.js application.css: application-214e0c0742f20b334e8a7776e0a4c71d.css
-
I don't see blueprint/screen.css in manifest.yml.
我看不出蓝图/屏幕。在manifest.yml css。
What am I missing?
我缺少什么?
4 个解决方案
#1
75
From http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
从http://guides.rubyonrails.org/asset_pipeline.html precompiling-assets
If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the precompile array
如果要包含其他清单或单个样式表和JavaScript文件,可以将它们添加到预编译数组中
This means that in your config/environments/production.rb, you set
这意味着在配置/环境/产品中。rb,设置
config.assets.precompile += %w( blueprint/screen.css blueprint/print.css )
or a catchall:
或一个包罗万象的:
config.assets.precompile += %w( *.css *.js )
#2
3
I added a reference to the blueprint stylesheets in my application.css file. This way, I do not have to change the layout to modify the stylesheets, I simply need to modify the application.css file, run rake assets:precompile
, and restart the webserver (if webrick or similar).
我在应用程序中添加了对blueprint样式表的引用。css文件。这样,我就不必修改布局来修改样式表,我只需要修改应用程序。css文件,运行rake资产:预编译,重新启动webserver(如果是webrick或类似的)。
My application.css currently looks like this:
我的应用程序。css目前看起来是这样的:
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree ./blueprint
*= require_tree .
*/
#3
2
You may want to precompile your assets on production as described above. And if you use capistrano you may do it after code update:
您可能希望像上面描述的那样在生产环境中预编译您的资产。如果你使用capistrano,你可以在代码更新后进行:
require 'bundler/capistrano'
after 'deploy:update_code' do
run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
end
#4
2
From my own experience with this problem, where I was also going through the excellent RoR tutorial by Michael Hartl, there was one step that I think might be left out at this point...
根据我自己对这个问题的经验,我也正在学习Michael Hartl的出色的RoR教程,我认为有一个步骤可能会在这一点上被遗漏……
bundle exec rake assets:precompile
git add public/assets
git commit -m "vendor compiled assets"
git push heroku
I found this here.
我发现在这里。
#1
75
From http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
从http://guides.rubyonrails.org/asset_pipeline.html precompiling-assets
If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the precompile array
如果要包含其他清单或单个样式表和JavaScript文件,可以将它们添加到预编译数组中
This means that in your config/environments/production.rb, you set
这意味着在配置/环境/产品中。rb,设置
config.assets.precompile += %w( blueprint/screen.css blueprint/print.css )
or a catchall:
或一个包罗万象的:
config.assets.precompile += %w( *.css *.js )
#2
3
I added a reference to the blueprint stylesheets in my application.css file. This way, I do not have to change the layout to modify the stylesheets, I simply need to modify the application.css file, run rake assets:precompile
, and restart the webserver (if webrick or similar).
我在应用程序中添加了对blueprint样式表的引用。css文件。这样,我就不必修改布局来修改样式表,我只需要修改应用程序。css文件,运行rake资产:预编译,重新启动webserver(如果是webrick或类似的)。
My application.css currently looks like this:
我的应用程序。css目前看起来是这样的:
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree ./blueprint
*= require_tree .
*/
#3
2
You may want to precompile your assets on production as described above. And if you use capistrano you may do it after code update:
您可能希望像上面描述的那样在生产环境中预编译您的资产。如果你使用capistrano,你可以在代码更新后进行:
require 'bundler/capistrano'
after 'deploy:update_code' do
run "cd #{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
end
#4
2
From my own experience with this problem, where I was also going through the excellent RoR tutorial by Michael Hartl, there was one step that I think might be left out at this point...
根据我自己对这个问题的经验,我也正在学习Michael Hartl的出色的RoR教程,我认为有一个步骤可能会在这一点上被遗漏……
bundle exec rake assets:precompile
git add public/assets
git commit -m "vendor compiled assets"
git push heroku
I found this here.
我发现在这里。