Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I got NoMethodError: undefined method `rails_blob_path` when using active storage

I got a following error when using active storage in rails 6.

NoMethodError: undefined method `rails_blob_path' for #<Module:0x00007fb91cb006a8>

My env

  • rails 6.0.0(api mode)
  • ruby '2.6.3'

I already installed active storage and execute migrate

config/environments/development.rb

config.active_storage.service = :local

Model

class Contract < ApplicationRecord
  ...
  has_one_attached :original_file
end

Serializer

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.

like image 231
Ryo Masuda Avatar asked Dec 02 '25 00:12

Ryo Masuda


1 Answers

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.

like image 192
Mephistt Avatar answered Dec 04 '25 14:12

Mephistt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!