如何构建任务“资产:预编译”

发布于 2024-12-01 14:26:39 字数 155 浏览 1 评论 0原文

我在生产服务器上遇到该错误,但无法找出原因。运行此命令时会发生这种情况:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦回旧景 2024-12-08 14:26:39

这很可能是由于您的 config/application.rb 不需要 rails/all (默认),但某些自定义需要。

要解决此问题,请将以下内容添加到 config/application.rb 中:

require 'sprockets/railtie'

This is most likely due your config/application.rb not requiring rails/all (the default), but some custom requires.

To resolve this, add the following to config/application.rb:

require 'sprockets/railtie'
北恋 2024-12-08 14:26:39

我纯粹出于习惯在一个仅 API 应用程序的根目录中运行这个命令,当然,该应用程序没有任何资产。

I was running this command -- out of sheer habit -- in the root of an API-only app, which, of course, has no assets.

§对你不离不弃 2024-12-08 14:26:39

我知道这是一篇旧帖子,但我认为如果我将其添加到答案中,它可能会对某人(可能是我未来的自己)有所帮助。

添加到Capfile(或deploy.rb)

load 'deploy/assets'

将其添加到application.rb

require 'sprockets/railtie'

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)

load 'deploy/assets'

add this to application.rb

require 'sprockets/railtie'
甚是思念 2024-12-08 14:26:39

我认为这可能是因为您在生产中不需要资产宝石。默认情况下,rails 期望您在生产中预编译资产。在 config/application.rb 中更改此设置:

注释掉这一行:

Bundler.require *Rails.groups(:assets => %w(开发测试))

并取消注释这一行:

Bundler.require(:default, :assets, Rails.env)

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:

Bundler.require *Rails.groups(:assets => %w(development test))

And uncomment this line:

Bundler.require(:default, :assets, Rails.env)

甜`诱少女 2024-12-08 14:26:39

这很奇怪。你可以随时尝试添加

load "sprockets/assets.rake"

到你的 Rakefile 中。它应该包含在 ActionPack Railtie 中。

我的 Rakefile 包含:

require File.expand_path('../config/application', __FILE__)
Qnm::Application.load_tasks

That's strange. You could always try adding

load "sprockets/assets.rake"

to your Rakefile. It should be included by the actionpack railtie.

My Rakefile contains:

require File.expand_path('../config/application', __FILE__)
Qnm::Application.load_tasks
标点 2024-12-08 14:26:39

这对我有用。
applications.rb 中添加 require "sprockets/railtie"
并创建一个空的清单文件app/assets/config/manifest.js

This worked for me.
Add require "sprockets/railtie" in applications.rb.
And create an empty manifest file app/assets/config/manifest.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文