Rails 3.1 资源无法在 ActiveAdmin 的生产环境中正确加载
我将 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 技术交流群。

发布评论
评论(2)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您必须使用 image-url 而不是 url。在生产环境中,Rails 3.1 为所有图像设置了哈希值。这样您就可以在部署后轻松使它们过期。这是一个很好的功能,因为浏览器可以像这样更好地缓存资源。您应该使用的代码:
Rails 3.1 将数字放入所有资源中,因为此变量是在 production.rb 中设置的,
您也可以将其设置为 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:
Rails 3.1 puts digets in all the assets because this variable is set in production.rb
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.