lundi 19 août 2019

Image not showing for multiple image upload with active storage

I have followed a tutorial on how to upload multiple images using active record. I have installed active record, added my associations to my model and when I create a Service (my model) everything seems to be working when I upload 3 images i.e no Active Record errors however I cannot see my images on the FE, all I see is a broken images.

When I go into Rails c and type Service.images.last I can see that images is nil. Does anyone know why this is?

Is there anything else you need to know or see from me?

Thank you

My code to show the image:

<%=@service.images.each do  |img| %>
  <%= cl_image_tag @service.images, crop: :fill, class: 'card-image', class: 'card-image-show'%>
 <%end %>


Rails c

  Service Load (59.6ms)  SELECT  "services".* FROM "services" ORDER BY "services"."id" DESC LIMIT $1  [["LIMIT", 1]]
=> #<ActiveStorage::Attached::Many:0x00007fffc3ff08a0 @name="images", @record=#<Service id: 14, name: "Test Carpet cleaning", description: "Lorem Ipsum is simply dummy text of the printing a...", picture_url: nil, video: nil, category: "carpet cleaning", created_at: "2019-08-19 12:32:35", updated_at: "2019-08-19 12:32:35", photo: nil, images: nil>, @dependent=:purge_later>

Service model

class Service < ApplicationRecord
  has_many_attached :images
  mount_uploader :photo, PhotoUploader
end


I would like my 3 images to display on the FE

Aucun commentaire:

Enregistrer un commentaire