Saturday, May 31, 2008

begin

Now for the begin statement:

begin
Record.transaction do

The Record.transaction do is nice and descriptive and tells the app that we want to record a transaction... right? Well, I would think so... breaking this up we see that Record is a class (because it starts with a Capitalization... ) But I have not defined Record anywhere so it must be a built in class in Ruby... I have searched for it but cannot find it... any help here?

The .transaction I did find out and is explained pretty well here:
http://api.rubyonrails.org/
by going to the file:
vendor/rails/activerecord/lib/active_record/transactions.rb

in a nutshell we are using .transaction because we want the insert to our database to be done only if the whole insertion succeeds. Thats why transaction is called a protective block... If it does not succeed then we can role the transaction back... no harm.

1 comment:

JEG2 said...

The Record class was generated for you when you told Rails to create the model. It should be in app/models/record.rb.