如何构建任务“资产:预编译”
我在生产服务器上遇到该错误,但无法找出原因。运行此命令时会发生这种情况:
bundle exec rake assets:precompile RAILS_ENV=production
我正在使用 Rails 3.1.0.rc6
I'm getting that error on my production server, and can't figure out why. It happens when running this command:
bundle exec rake assets:precompile RAILS_ENV=production
I'm using Rails 3.1.0.rc6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这很可能是由于您的
config/application.rb
不需要rails/all
(默认),但某些自定义需要。要解决此问题,请将以下内容添加到 config/application.rb 中:
This is most likely due your
config/application.rb
not requiringrails/all
(the default), but some custom requires.To resolve this, add the following to
config/application.rb
:我纯粹出于习惯在一个仅 API 应用程序的根目录中运行这个命令,当然,该应用程序没有任何资产。
I was running this command -- out of sheer habit -- in the root of an API-only app, which, of course, has no assets.
我知道这是一篇旧帖子,但我认为如果我将其添加到答案中,它可能会对某人(可能是我未来的自己)有所帮助。
添加到Capfile(或deploy.rb)
将其添加到application.rb
I know this is an old post but I thought it might help someone (probably my future self) if I added this to the answers.
add to Capfile (or deploy.rb)
add this to application.rb
我认为这可能是因为您在生产中不需要资产宝石。默认情况下,rails 期望您在生产中预编译资产。在 config/application.rb 中更改此设置:
注释掉这一行:
并取消注释这一行:
I think that it might be because you aren't requiring the asset gems in production. By default rails expects that you are pre-compiling your assets in production. Change this in config/application.rb:
Comment out this line:
And uncomment this line:
这很奇怪。你可以随时尝试添加
到你的 Rakefile 中。它应该包含在 ActionPack Railtie 中。
我的 Rakefile 包含:
That's strange. You could always try adding
to your Rakefile. It should be included by the actionpack railtie.
My Rakefile contains:
这对我有用。
在
applications.rb
中添加require "sprockets/railtie"
。并创建一个空的清单文件
app/assets/config/manifest.js
This worked for me.
Add
require "sprockets/railtie"
inapplications.rb
.And create an empty manifest file
app/assets/config/manifest.js