attr_json: Defining attr_json attributes on the parent class results in "NoMethodError: super: no superclass method"
(note from maintainer: There are a variety of things that could cause a NoMethodError. If you have such an error but don’t know why, please file a separate Issue or, even better, start at topic in Discussions, instead of adding a “me too” here. Thank you, and thanks for getting in touch!)
I’m trying to upgrade to the latest attr_json
and running into an issue that was not happening with the previous version of attr_json (we’ve been using this gem for many years).
I have several cases where I define the attr_json
attribute in the parent (abstract) class, then use it in the child class. With the new version, I can only get it to work if I define the attribute in each of the child classes.
Is this expected behaviour, and if so, can you suggest how to get around this?
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 20 (9 by maintainers)
The
super
method I am guessing it is – should be calling the “setter” method that was provided by the call to Railsattribute
.attr_json 2.0 always creates an underlying Rails attribute, for more natural/consistent Rails integration. And relies on it being there and being called by the setter, for some behaviors to work. Such as rails dirty tracking, and full casting.
So if it’s not there… things might break, guarding the call to super with a condition to check super exists may not be sufficient.
So I’m very curious under what conditions the super method ordinarily provided by rails
attribute
would not exist. I can’t reproduce it. And might need to in order to fix things for those conditions. Which I am definitely interested in doing! So appreciate your help!