# Static scaffolding and transactions

**URL:** <https://www.ruby-forum.com/t/static-scaffolding-and-transactions/138444>\
**Category:** Rails\
**Created:** [May 23, 2008, 3:11am UTC](https://www.ruby-forum.com/t/static-scaffolding-and-transactions/138444 "2008-05-23T03:11:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [May 23, 2008, 3:11am UTC](https://www.ruby-forum.com/t/static-scaffolding-and-transactions/138444/1 "2008-05-23T03:11:16Z")

</div>

Hi,  
I’m a Java/J2EE developer that is new to Rails. I’ve read through most  
of _AWD with Rails_ so that I have a basic understanding of what  
Active Record can do. I’ve also done a bit of reading up on the switch  
to RESTful controllers in Rails 2.0.

I’m developing an app in Rails 2.0.2 with Ruby 1.8.6. I noticed that  
static scaffolding generates logic in the controllers that modifies  
the database such as @myActiveRecord.save (likewise for  
update\_attributes and destroy).  
The Rails API saith that save and destroy will be wrapped in a  
transactional context, but what about update? Is that automatically  
transactional? If not, then to this Java developer’s eyes, this seems  
to be a mistake.

Regards,  
Alan

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [May 23, 2008, 9:52am UTC](https://www.ruby-forum.com/t/static-scaffolding-and-transactions/138444/2 "2008-05-23T09:52:55Z")

</div>

Save, destroy and update\_attributes are in transactional method. If  
there’s an error while executing database it would be rolled back, the  
error can be handled by using errors.add(:attribute, “your error message  
here”).

But you can use locking method for more secure transaction it would be  
nice transaction. like a NameModel.find(params[:id], :lock=\> true), it  
will hold other transactions which is wanting to update or access  
NameModel.find(params[:id].

Ruby has also ActiveRecord Transaction, like :  
ActiveRecord.transaction do  
…  
end

or

YourModelName.transaction do  
…  
end

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [May 23, 2008, 8:29pm UTC](https://www.ruby-forum.com/t/static-scaffolding-and-transactions/138444/3 "2008-05-23T20:29:25Z")

</div>

Dear Reinhart,  
Thanks that’s just what I wanted to know.

Regards,  
Alan

On May 23, 3:52 am, Rails T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
