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
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
Dear Reinhart,
Thanks that’s just what I wanted to know.
Regards,
Alan
On May 23, 3:52 am, Rails T. [email protected]