How to display images in the list action of rails_admin?

rails-admin, ruby-on-rails

Solution

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

Problem

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?

Original source