-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Active Storage: method_missing': undefined method
has_one_attached'
#3025
Comments
I think I've had the same issue. I was trying to configure model inside rails_admin initializer using |
@dmilisic thank you very much! It saved me a lot of time. :) But, any idea why it should be quoted? |
Initalizers are run before your application code runs. Models are interpreted only when needed (on a firs request perhaps). But if you reference a model in the initializer using a constant ie. It seems that |
If you don't use require "rails/all', you'll need to require "active_storage" in your application.rb file |
Same issue here, is there any fix? |
declaring this on model solved the problem for me `
end reference https://github.com/sferik/rails_admin/issues/2990#issuecomment-378220331 |
I'm having this problem too. Here's a strange thing: if I comment out But I don't want to have to comment out all active storage functions each time I start the server. Rails version = 5.2.1 Here's the model:
Here's the application.rb file:
Here's the Error Message:
@tteurs - declaring it on the model like you did above didn't help. |
Full stack trace might be helpful. The problem might be in initalizers. I had |
Hey guys, Not sure if this is related, but thought I might bring it up -- Shopify/bootsnap#218 |
I just ran into this and the bug @sideshowbandana mentions, Shopify/bootsnap#218, was the cause. |
I solve my issue removing all configuration model from initializer( rails_admin.rb ) and putting each configuration in the respective model. |
Fixed by Shopify/bootsnap#249 |
I'm getting this error too, but in my case is on Papertrail configuration: RailsAdmin.config do |config|
...
config.audit_with :paper_trail, 'User', 'PaperTrail::Version'
...
end User model: class User < ApplicationRecord
...
has_one_attached :avatar
...
end The error message:
Full stacktrace
Any ideas in how to solve this? |
Can you post the code of your rails_admin initializer? Or perhaps line 18? |
Line 18 it is the papertrail configuration: config.audit_with :paper_trail, 'User', 'PaperTrail::Version' |
@dmilisic thank you for the support! We have managed to solve the problem. The
So we just copy the constant to the |
Great to hear you managed to solve this issue. But the question remains: why was even |
Yes, it use a constant from
Not directly at least. Maybe all helpers are load before models!? |
@dmilisic #3025 (comment) |
I ignored this thread because I thought it would not solve my issue. Turns out I'm completely wrong. Thank you so much! @dmilisic |
thanks a lot @dmilisic, your solution to use a string instead of a constant helped me a lot!! |
At least up to 5.2.4.3, ActiveStorage seems to initialize and inject its methods into ActiveRecord after Rails config/initializers are loaded. For example, if you have a User model using I added this code, taken from # config/application.rb
require "active_storage/attached"
ActiveSupport.on_load(:active_record) do
extend ActiveStorage::Attached::Macros
end |
Hello guys, I'm facing a issue while using active storage with rails_admin.
What's happening is that I've model called Product which should have a image. I've installed active storage by running the following commands:
After that, I've added a new attibute on my Model as:
However, rails does not recognize it as a method:
I've created a application from the scratch without rails_admin and it worked fine.
Note: I'm using rails 5.2.0 and ruby 2.5.1
Any ideas?
The text was updated successfully, but these errors were encountered: