'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 1:[1]
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/
Solution 2:[2]
My issue was also in storage.yml but it was because I had embedded Ruby in a section of code that had been commented, but the Ruby tag was not commented:
# digitalocean_spaces:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:digitalocean_spaces, :access_key_id) %>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Oscar Valdez Esquea |
| Solution 2 | therealrodk |
