I have a self-associating model which allows the user to define a "parent photo", in order to group them together.
My model:
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
And in my rails_admin initializer:
..
config.model Photo do
list do
field :image
field :associated_photos
end
end
end
How do I retrieve the actual thumbnail for use in the list action?
It seems like this is addressed on the wiki under the heading "Fields - Output formatting."
Will something like this work?
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
To show the image field:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With