Rails 3.1 资源无法在 ActiveAdmin 的生产环境中正确加载

发布于 12-13 04:30 字数 764 浏览 4 评论 0原文

我将 ActiveAdmin 与 Rails 3.1 一起使用。该 gem 使用的唯一图像(据我所知)是表格标题行中的排序箭头。在开发中,CSS 正确引用了这些图像:

table.index_table th.sortable a {
    background: url("/assets/active_admin/orderable.png") no-repeat 0 4px;
    padding-left: 13px;
}

在生产中,CSS 没有正确引用这些图像,导致 404:

table.index_table th.sortable a {
    background: url("/images/active_admin/orderable.png") no-repeat 0 4px;
    padding-left: 13px;
}

以下是我的 Gemfile 中的相关内容:

gem 'rails', '3.1.1'

group :assets do
  gem 'sass-rails', '~> 3.1.0'
  gem 'coffee-rails', '~> 3.1.0'
  gem 'uglifier'
end

gem 'activeadmin', :git => 'git://github.com/gregbell/active_admin.git'

I'm using ActiveAdmin with Rails 3.1. The only images (that I'm aware of) that this gem uses are sorting arrows in the header rows of tables. In development, the CSS properly references these images:

table.index_table th.sortable a {
    background: url("/assets/active_admin/orderable.png") no-repeat 0 4px;
    padding-left: 13px;
}

In production, the CSS does not properly reference these images, resulting in a 404:

table.index_table th.sortable a {
    background: url("/images/active_admin/orderable.png") no-repeat 0 4px;
    padding-left: 13px;
}

Here is the relevant content from my Gemfile:

gem 'rails', '3.1.1'

group :assets do
  gem 'sass-rails', '~> 3.1.0'
  gem 'coffee-rails', '~> 3.1.0'
  gem 'uglifier'
end

gem 'activeadmin', :git => 'git://github.com/gregbell/active_admin.git'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

等风也等你2024-12-20 04:30:59

您必须使用 image-url 而不是 url。在生产环境中,Rails 3.1 为所有图像设置了哈希值。这样您就可以在部署后轻松使它们过期。这是一个很好的功能,因为浏览器可以像这样更好地缓存资源。您应该使用的代码:

table.index_table th.sortable a {
  background: image-url("active_admin/orderable.png") no-repeat 0 4px;
  padding-left: 13px;
}

Rails 3.1 将数字放入所有资源中,因为此变量是在 production.rb 中设置的,

config.assets.digest = true

您也可以将其设置为 false,但我不建议这样做。

如果您无法触摸 active_admin 的 css,则必须将 active_admin 升级到最新版本,然后重试。

You have to use image-url instead of url. In production Rails 3.1 sets a hash to all your images. Like that you can expire them easily after a deploy. This is a nice feature because the browser can cache the assets better like this. The code you should use:

table.index_table th.sortable a {
  background: image-url("active_admin/orderable.png") no-repeat 0 4px;
  padding-left: 13px;
}

Rails 3.1 puts digets in all the assets because this variable is set in production.rb

config.assets.digest = true

you can set that to false as well but i dont suggest it.

If you cant touch the css for active_admin than you have to upgrade active_admin to the latest version and try again.

慕烟庭风2024-12-20 04:30:59

为此,最终向 ActiveAdmin git 存储库提交了问题。解决方案(对我来说)是将我的 sass-rails gem 升级到 3.1.4。

gem 'rails', '3.1.1'

group :assets do
  gem 'sass-rails', '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.0'
  gem 'uglifier'
end

gem 'activeadmin', :git => 'git://github.com/gregbell/active_admin.git'

There ended up being an issue submitted to the ActiveAdmin git repository for this. The solution (for me) was to upgrade my sass-rails gem to 3.1.4.

gem 'rails', '3.1.1'

group :assets do
  gem 'sass-rails', '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.0'
  gem 'uglifier'
end

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