I got a following error when using active storage in rails 6.
NoMethodError: undefined method `rails_blob_path' for #<Module:0x00007fb91cb006a8>
I already installed active storage and execute migrate
config.active_storage.service = :local
class Contract < ApplicationRecord
...
has_one_attached :original_file
end
class ContractSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
attributes :id, :original_file
def original_file
Rails.application.routes.default_url_options[:host] = 'localhost:3000'
Rails.application.routes.url_helpers.rails_blob_path(object.original_file, only_path: true) if object.original_file.attached?
end
end
If you have any tips, Please let me know if you know anything about this. Thank you.
The include statement and the full path to rails_blob_path method seem to be OK.
It looks like there is a naming issue.
You have created attribute and method with the same name.
Try to change one of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With