This project is archived and is in readonly mode.

#6665 new
Jakob S

Block syntax for update_attributes

Reported by Jakob S | April 3rd, 2011 @ 10:48 AM

ActiveRecord::Base#new and #create accepts both a Hash of attributes and a block:

  User.create(:first_name => 'Jamie') do |u|
    u.is_admin = false
  end

This patch adds that same functionality to update_attributes:

  user.update_attributes(:first_name => 'Jamie') do |u|
    u.is_admin = false
  end
  user.first_name #=> 'Jamie'
  user.is_admin   #=> false

A use case for this is in the administration area, where authenticated users might be allowed to update attributes that are otherwise protected.

Edited by Rohit Arondekar for formatting.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages