Ruby on rails 如何在rails_admin的列表操作中显示图像?
我有一个自关联模型,允许用户定义一张“父照片”,以便将它们组合在一起 我的模型:Ruby on rails 如何在rails_admin的列表操作中显示图像?,ruby-on-rails,rails-admin,Ruby On Rails,Rails Admin,我有一个自关联模型,允许用户定义一张“父照片”,以便将它们组合在一起 我的模型: class Photo < ActiveRecord::Base attr_accessible :image, :parent_photo has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" } validates_attachment :imag
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
如何检索用于列表操作的实际缩略图?这似乎是在“字段-输出格式”标题下解决的 像这样的东西行吗
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
config.model-Photo-do
列出要做的事
字段:image do
格式化的u值do
bindings[:view].tag(:img,{:src=>bindings[:object].image.url})以显示图像字段:
config.model Photo do
list do
field :image do
pretty_value do
bindings[:view].tag(:img, { :src => bindings[:object].image.url(:thumb) })
end
end
end
end
这对我很有效(只使用.image
而不是.image.url
)。谢谢
config.model Photo do
list do
field :image do
pretty_value do
bindings[:view].tag(:img, { :src => bindings[:object].image.url(:thumb) })
end
end
end
end