I've followed 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. No luck in both 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
images
really plural? If so you will need to loop through them. – Rockwell Rice<% c.images.each do |i| %> <%= url_for(i) %> <% end %>
But no use. Also tried image_tag and without any, just "i" – amazingbot