我有一个自关联模型,它允许用户定义“父照片”,以便将它们组合在一起。
我的型号:
class Photo < ActiveRecord::Base
attr_accessible :image, :parent_photo
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
validates_attachment :image,
:presence => true,
:size => { :in => 20..2000.kilobytes },
:content_type => { :content_type => [ 'image/jpeg', 'image/png' ] }
belongs_to :parent, class_name: "Photo", foreign_key: :parent_photo
def associated_photos
Photo.find_by_parent_photo(id)
end
end
在我的 rails_admin 初始化程序中:
..
config.model Photo do
list do
field :image
field :associated_photos
end
end
end
如何检索用于列表操作的实际缩略图?
最佳答案
这似乎是在 the wiki 上的“字段 - 输出格式”标题下解决的。
这样的事情会起作用吗?
config.model Photo do
list do
field :image do
formatted_value do
bindings[:view].tag(:img, { :src => bindings[:object].image.url }) << value
end
field :associated_photos
end
end
关于ruby-on-rails - 如何在 rails_admin 的列表操作中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11551214/