Undefined method `attachment_path or URL for #
Solved:-
Use this code in output file.
<%if orders.avatar.attached?%> <%= image_tag main_app.url_for(orders.avatar) %> <%end%>
if you want to save the image URL in the database you can add this to your controller or model.
:- main_app.url_for(model.”has_one_attached attribute name” ex:-avtar)
Edit image size:- variant(resize: “200×400”)
<%= image_tag main_app.url_for(orders.avatar.variant(resize: “200×400”)) %>
How to generate url for rails active storage image and file
Inside model:-
class VerifyIdentity < ApplicationRecord
has_one_attached :upload_verifydata
def image_url
Rails.application.routes.url_helpers.url_for(image) if image.attached?
end
end
for more reference:-https://www.timdisab.com/uploading-files-in-ruby-on-rails-with-active-storage