Ruby on Rails latest stable (v7.1.3.2) - 1 note - Class: AttributeAssignment

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v4.2.9) is shown here.

These similar methods exist in v7.1.3.2:

assign_attributes(new_attributes) public

Allows you to set all the attributes by passing in a hash of attributes with keys matching the attribute names (which again matches the column names).

If the passed hash responds to permitted? method and the return value of this method is false an ActiveModel::ForbiddenAttributesError exception is raised.

cat = "Gorby", status: "yawning")
cat.attributes # =>  { "name" => "Gorby", "status" => "yawning", "created_at" => nil, "updated_at" => nil}
cat.assign_attributes(status: "sleeping")
cat.attributes # =>  { "name" => "Gorby", "status" => "sleeping", "created_at" => nil, "updated_at" => nil }

New attributes will be persisted in the database when the object is saved.

Aliased to attributes=.

Show source
Register or log in to add new notes.
September 5, 2012 - (v3.2.1 - v3.2.8)
1 thank


Note that in the example shown in the documentation, `user.assign_attributes({ :name => ‘Josh’, :is_admin => true })` would raise a `ActiveModel::MassAssignmentSecurity::Error` and would not actually update, contrary to what the example seems to demonstrate.