How to display multiple images in ActiveAdmin

I use paperclip to upload multiple images. I also use Active Admin. So far, I have been able to upload multiple images and associate them with my product model. I can also display the "names" of all related images on the index page. However, I cannot learn how to display all images (not just names) on my model product display page. Please find the code below.

\ App \ models \ product.rb

has_many :images, :dependent => :destroy accepts_nested_attributes_for :images, :allow_destroy => true 

\ App \ models \ image.rb

 belongs_to :product has_attached_file :image, :styles => { :thumb=> "100x100>", :small => "300x300>", :large => "600x600>" } 

\ application \ Admin \ products.rb

 index do column "Images" do |product| product.images.map(&:image_file_name).join("<br />").html_safe end end show do |product| attributes_table do row "Images" do ul do li do image_tag(product.images.first.image.url(:small)) end li do image_tag(product.images.second.image.url(:small)) end li do image_tag(product.images.last.image.url(:small)) end end end end end 

I found something that works, but it's really bad programming. I currently have 3 images associated with each product, and I use the code above in my show block. Please suggest a better way to do this.

+6
source share
1 answer

Do you mean that you need to display each image not only from three? If yes, try

 row "Images" do ul do product.images.each do |img| li do image_tag(img.image.url(:small)) end end end end 
+12
source

All Articles