Search code examples
ruby-on-railsrubyactiveadminrails-activestorageruby-on-rails-5.2

Active storage images not showing in activeadmin rails


Using active storage to store images which are working fine. Issue I face is that when I image_tag image it shows # instead of image.

Here is the code products.rb

has_many_attached :photos

in active_admin

row "Images" do |p|
  p.photos.attachments.each do |photo|
    image_tag photo
  end
end

it not displaying images. it check with byebug also the url is fine but images not display and it shows this

enter image description here

only this one works

row "Images" do |p|
    image_tag p.photos.attachments.last
end

Solution

  • You need to use the url_for to display the images, something like below

    row "Images" do |p|
      ul do
        p.photos.each do |photo|
          li do
            image_tag url_for(photo)
          end
        end
      end
    end