Home > OS >  Can't resolve image into URL: undefined method `attachment_url' for #<#<Class:0x0000
Can't resolve image into URL: undefined method `attachment_url' for #<#<Class:0x0000

Time:07-29

image_tag doesn't work from me for some reason.

  • I have installed Active Storage gem
  • I have has_many_attached :images in my Bug model
  • I have tried using polymorphic_url, and url_for. It doesn't work either
  • Here is what my error looks like

CodePudding user response:

Please replace image_tag like below. @bug.images is collection of activestorage objects so you need to access the image path like image.key

<%=image_tag(img.key)%>

Hope it helps.

CodePudding user response:

I got done with my task by using cloudinary with active storage, and using its image tag like this:

<%if @bug.bug_screenshot.attached? %> <%= cl_image_tag(@bug.bug_screenshot.key, width: 300, height: 300)%> <% end %>

  • Related