3
votes

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!

2
Did you run rails active_storage:install ?andreofthecape
Yes I did. Everything was working perfectly fine for about a week before I started seeing this error, rails active_storage:install was one of the first things I did. I have the active storage tables in my schema and the pictures are associated with the correct model in my back end.AngeloS

2 Answers

4
votes

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.

0
votes

In my case (Legacy APP using Rails 5.1.4 and ruby 2.4.2) what worked was altering the migration file created by the activestorage install from this:

ActiveStorage::CreateTables

To this:

ActiveStorageCreateTables

The file can be located in db/migrate/