You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If using default_value_for within a subclass of another model, then the class instance initialization will fail with: ArgumentError (wrong number of arguments (given 2, expected 0..1))
This is version 3.3.0 and using all combinations of Ruby 2.6.5 and 2.7, and with Rails 5.2 and 6.0.
For example consider the classes:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class Example < ApplicationRecord
default_value_for :name, "Hello"
end
Then calling Example.new will abort with the error. If on the other hand that were to subclass directly from ActiveRecord::Base instead of ApplicationRecord then it works fine.
I think I've tracked it down to calling super() within the initialize method. If I replace
the code in default_value_for.rb
If using
default_value_for
within a subclass of another model, then the class instance initialization will fail with:ArgumentError (wrong number of arguments (given 2, expected 0..1))
This is version 3.3.0 and using all combinations of Ruby 2.6.5 and 2.7, and with Rails 5.2 and 6.0.
For example consider the classes:
Then calling
Example.new
will abort with the error. If on the other hand that were to subclass directly fromActiveRecord::Base
instead ofApplicationRecord
then it works fine.I think I've tracked it down to calling
super()
within theinitialize
method. If I replacethe code in
default_value_for.rb
with
then it seems to work fine. Though I am not comfortable that this is the correct change to make.
The text was updated successfully, but these errors were encountered: