diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 4dfe8655fe..fd84007023 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -466,8 +466,8 @@ module ActiveRecord # # Attributes marked as readonly are silently ignored if the record is # being updated. - def save(*args, &block) - create_or_update(*args, &block) + def save(*args, **options, &block) + create_or_update(*args, **options, &block) rescue ActiveRecord::RecordInvalid false end @@ -499,8 +499,8 @@ module ActiveRecord # being updated. # # Unless an error is raised, returns true. - def save!(*args, &block) - create_or_update(*args, &block) || raise(RecordNotSaved.new("Failed to save the record", self)) + def save!(*args, **options, &block) + create_or_update(*args, **options, &block) || raise(RecordNotSaved.new("Failed to save the record", self)) end # Deletes the record in the database and freezes this instance to diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 24ac53103b..98e46a4af0 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -310,11 +310,11 @@ module ActiveRecord with_transaction_returning_status { super } end - def save(*) #:nodoc: + def save(*, **) #:nodoc: with_transaction_returning_status { super } end - def save!(*) #:nodoc: + def save!(*, **) #:nodoc: with_transaction_returning_status { super } end diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index d21716404e..86bfb661dc 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -43,13 +43,13 @@ module ActiveRecord # The validation context can be changed by passing context: context. # The regular {ActiveRecord::Base#save}[rdoc-ref:Persistence#save] method is replaced # with this when the validations module is mixed in, which it is by default. - def save(options = {}) + def save(**options) perform_validations(options) ? super : false end # Attempts to save the record just like {ActiveRecord::Base#save}[rdoc-ref:Base#save] but # will raise an ActiveRecord::RecordInvalid exception instead of returning +false+ if the record is not valid. - def save!(options = {}) + def save!(**options) perform_validations(options) ? super : raise_validation_error end