From c247370cae6ce681648b8272bf18562addea2353 Mon Sep 17 00:00:00 2001 From: schneems Date: Fri, 9 May 2014 17:37:11 -0500 Subject: [ci skip] add example to AR#assign_attributes --- activerecord/lib/active_record/attribute_assignment.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/lib') 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 permitted? method and the return value # of this method is +false+ an ActiveModel::ForbiddenAttributesError # 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. + # attributes = 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." -- cgit v1.2.3