How to get url of Active Storage image How to get url of Active Storage image ruby-on-rails ruby-on-rails

How to get url of Active Storage image


For my User which has_one_attached :avatar I can get the url in my views with <%= image_tag url_for(user.avatar) %>.So, in controller I would use just url_for(user.avatar)

For Category which has_one_attached :image:

url_for(category.image)


Also try @object.image.service_url. This will give you the url where the image is saved. I.E. url to amazon s3 storage.


Please follow this for fetching images( in case if you are using has_many_attached)

Model.images.map{|img| ({ image: url_for(img) })}