Do not depend on the default parameter being set in Person#initialize.
ActiveRecord 5.2.x occasionally calls with a nil parameter explicitly provided, so using default arguments does not work.
This commit is contained in:
parent
93b0e1eb22
commit
25e9728fae
1 changed files with 2 additions and 0 deletions
|
|
@ -185,6 +185,8 @@ class Person < ApplicationRecord
|
|||
# end
|
||||
# will not work! The nil profile will be overriden with an empty one.
|
||||
def initialize(params={})
|
||||
params = {} if params.nil?
|
||||
|
||||
profile_set = params.has_key?(:profile) || params.has_key?("profile")
|
||||
params[:profile_attributes] = params.delete(:profile) if params.has_key?(:profile) && params[:profile].is_a?(Hash)
|
||||
super
|
||||
|
|
|
|||
Loading…
Reference in a new issue