1

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

2 Answers 2

6

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
Sign up to request clarification or add additional context in comments.

3 Comments

i updated my answer render image inside a ul & li can you try that once? It worked for me.
but whats the diff?
i'm not sure but i think as you're looping through multiple items it was returning an array of #. Where as when you use last you're directly rendering it with a image_tag. And when you use ul & li to render multiple items html is returned and it was rendering it. that makes the difference i guess.
0

I did not face any issues doing it this way for multiple attachments:

if resource.photos.attached?
  row "Photos" do |resource|
    resource.photos.map{|photo| image_tag url_for photo}
  end
end

I don't know why @uday would suggest ul and li. It seems like an "XY solution".

1 Comment

I mean the OP was missing url_for. The issue is not solved with ul and li. It is solved with url_for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.