Skip to content

Commit

Permalink
Add the update_only option to accepts_nested_attributes_for attribute…
Browse files Browse the repository at this point in the history
…s writers
  • Loading branch information
olivier-thatch committed Oct 12, 2023
1 parent 6f56a4a commit 41923fa
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,25 @@ class Post < ApplicationRecord
end
----

=== `accepts_nested_attributes_for` Update Only Option [[accepts_nested_attributes_for-update_only-option]]

Define the `update_only` option to the `accepts_nested_attributes_for` attributes writers.

[source,ruby]
----
# bad
class Member < ApplicationRecord
has_one :avatar
accepts_nested_attributes_for :avatar
end
# good
class Member < ApplicationRecord
has_one :avatar
accepts_nested_attributes_for :avatar, update_only: true
end
----

=== `save!` [[save-bang]]

When persisting AR objects always use the exception raising bang! method or handle the method return value.
Expand Down

0 comments on commit 41923fa

Please sign in to comment.