aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2014-05-09 17:37:11 -0500
committerschneems <richard.schneeman@gmail.com>2014-05-09 17:37:11 -0500
commitc247370cae6ce681648b8272bf18562addea2353 (patch)
tree37b57a6355854f306d288be2f0604e95d5b346b7 /activerecord
parent7063e254bf2a24cda7d7f3e07ba50ac1b44a8d2f (diff)
downloadrails-c247370cae6ce681648b8272bf18562addea2353.tar.gz
rails-c247370cae6ce681648b8272bf18562addea2353.tar.bz2
rails-c247370cae6ce681648b8272bf18562addea2353.zip
[ci skip] add example to AR#assign_attributes
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_assignment.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_assignment.rb b/activerecord/lib/active_record/attribute_assignment.rb
index 30fa2c8ba5..5007e319da 100644
--- a/activerecord/lib/active_record/attribute_assignment.rb
+++ b/activerecord/lib/active_record/attribute_assignment.rb
@@ -11,6 +11,16 @@ module ActiveRecord
# If the passed hash responds to <tt>permitted?</tt> method and the return value
# of this method is +false+ an <tt>ActiveModel::ForbiddenAttributesError</tt>
# exception is raised.
+ #
+ # Example:
+ #
+ # cat = Cat.new(name: "Gorby", status: "yawning")
+ # cat.attributes # => {"name" => "Gorby", "status" => "yawning"}
+ # cat.assign_attributes(status: "sleeping")
+ # cat.attributes # => {"name" => "Gorby", "status" => "sleeping"}
+ #
+ # New attributes will be persisted to database when object is saved.
+ # <tt>attributes =</tt> is an alias.
def assign_attributes(new_attributes)
if !new_attributes.respond_to?(:stringify_keys)
raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."