ruby-on-railsactiverecordrails-activestorageuninitialized-constant

NameError Exception: uninitialized constant ActiveStorage::Attachment::ActiveStorage::Blob


I am trying to use my Rails database and keep running into this error. The database was working previously with no active storage issues until 5 days ago when it stopped and I started seeing this error:

*** NameError Exception: uninitialized constant ActiveStorage::Attachment::ActiveStorage::Blob

I have a .jbuilder file that is where the error is happening,

json.array! @campaigns do |campaign|
    byebug
    json.extract! campaign, :id, :title, :description, :goal, :campaign_end, :user_id, :current_amount, :ends, :percent_complete, :amount_left_to_fund, :owner, :successful
    json.photoUrl url_for(campaign.photo)
end

Where it says url_for(campaign.photo) I get the error. However, just typing campaign.photo shows the ActiveStorage instance with the campaign it is attached to:

#<ActiveStorage::Attached::One:0x00007febc64f91b0 @name="photo", @record=#<Campaign id: 7, title: "Surgery", description: "Lorem ipsum dolor sit amet, consectetur adipiscing...", goal: 5000, user_id: 8, campaign_end: "2019-05-31 16:00:00", created_at: "2019-05-01 14:20:14", updated_at: "2019-05-01 14:20:14", successful: false>, @dependent=:purge_later>

I am just trying to get the url for this active storage photo. I tried googling this error but haven't seen anything with this error message. Any help would be much appreciate!


Solution

  • I just ran into this issue and solved with the simplest solution.

    The storage.yml file had a block that ended up misaligned. Causing a yaml parse error and I imagine a whole list of load / initialize errors downstream.

    You can verify your yaml with a linter or by simply running Rails.application.config_for(:storage) from rails console.