This project is archived and is in readonly mode.
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
-
Jakob S April 3rd, 2011 @ 10:54 AM
/pwned by Lighthouse code formatting :(
Attached revised patch with docs for the changes.
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>