Dear ALL"
I would like to ask, what is it true that rails already supports transaction although we do not put ActiveRecord::Base.transaction in our ruby controller or model script? - My DB ENGINE is InnoDB -
I'm not quite sure what you're asking, but rails does wrap the validation, before_save, save and after_save sequence in a transaction.
I did test in web browser with putting delay process inside of script to make 2 concurrent process having collision, but the fact at final, they are handled with transaction, i do not put any ActiveRecord::Base.transaction or ModelName.transaction script there.
Example : They are 10 items in stock. 2 concurrent process wanted to take 1 item from stocks. If it is not having ActiveRecord::Base.transaction in method the result would be 9, but the fact is it is 8 (10-1-1). Look the tables process below without transaction in console (table 1) & web browser (table 2):
How come my test in console and web browser are difference ??
If you're just running a single mongrel/webrick instance then when you test with your browser you're not actually executed 2 things at the same time (since a rails instance only handles one request at a time).
Fred (PS: if you want to insert a delay, the sleep method is rather handier than counting to a million)