From 25e9728fae9646294c3bd14e8d9377925528abf6 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Sun, 9 Feb 2020 17:38:19 +0100 Subject: [PATCH] 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. --- app/models/person.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/person.rb b/app/models/person.rb index 8745a1179..64746200e 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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