instance method
attributes=
Ruby on Rails 3.2.22.5
Since v3.2.22.5 Last seen in v4.2.9Signature
attributes=(new_attributes)
Allows you to set all the attributes at once by passing in a hash with keys matching the attribute names (which again matches the column names).
If any attributes are protected by either attr_protected or attr_accessible then only settable attributes will be assigned.
class User < ActiveRecord::Base attr_protected :is_admin end user = User.new user.attributes = { :username => 'Phusion', :is_admin => true } user.username # => "Phusion" user.is_admin? # => false
Parameters
-
new_attributesreq
Source
# File activerecord/lib/active_record/attribute_assignment.rb, line 33
def attributes=(new_attributes)
return unless new_attributes.is_a?(Hash)
assign_attributes(new_attributes)
end
Defined in activerecord/lib/active_record/attribute_assignment.rb line 33
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::AttributeAssignment