# Update in transactions

**URL:** <https://www.ruby-forum.com/t/update-in-transactions/184433>\
**Category:** Rails\
**Created:** [March 2, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/update-in-transactions/184433 "2010-03-02T15:30:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [March 2, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/update-in-transactions/184433/1 "2010-03-02T15:30:21Z")

</div>

Can i update attributes in transaction… I mean while saving a record i  
do like this:-

object = Model.new(params[:model])  
Model.transaction do  
object.save!  
end

Can we also do it for updating a record… i mean like this:-

object = Model.find(:id)  
Model.transaction do  
object.update\_attributes!  
end

Obviously this chunk of code is not working, thats why i asked you  
people…

Thanks in advance

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [March 2, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/update-in-transactions/184433/2 "2010-03-02T16:54:12Z")

</div>

On Mar 2, 2:30 pm, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> object = Model.find(:id)  
> Model.transaction do  
> object.update\_attributes!  
> end
> 
> Obviously this chunk of code is not working, thats why i asked you  
> people…

Other than the fact that you’re passing an invalid argument to find  
and that update\_attributes probably requires you to pass an argument  
this should be fine (although obviously pointless unless you make  
several changes within the transaction.

Fred
