I'm following the rails ActiveStorage guide. I've successfully saved the image to the blob table in the local database (the attachment table is empty). But I can't seem to show it in the view:
<%= url_for(@comment.images) if @comment.images %>
does not work nor does:
<% @comments.each do |c| %>
<%= c.body %>
<%= url_for(c.images) if c.images %>
<% end %>
Showing other values of comment works, so this is specific to the images. I've also tried adding .url to "images." And I've tried image_tag instead of url_for. And looping through the images. And image_tag url_for (instead of using just one of them). And using representation. No luck in all of these cases. I'd really appreciate any help.
And my model
has_many_attached :images
application.js
//= require activestorage
import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"
Rails.start()
Turbolinks.start()
ActiveStorage.start()
controller
private
def comment_params
params.require(:comment).permit(:body, images: [])
end
representable?
could you please check the result for@comment.images.first.representable?
– Sampat BadheActive Storage Overview
documentation ? – Sampat Badhe<%= image_tag i.representation(resize: '500x500') %>
but nothing showed. ( "i" since I was looping through them) – amazingbot@comment.images.attached?
returns true or false? – Sampat Badhe