instance method attributes=

Ruby on Rails 3.2.22.5

Since v3.2.22.5 Last seen in v4.2.9

Available in: v3.2.22.5 v4.0.13 v4.1.16 v4.2.9

Signature

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_attributes req
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

Type at least 2 characters to search.

↑↓ navigate · open · esc close