# Adding data as a transaction

**URL:** <https://www.ruby-forum.com/t/adding-data-as-a-transaction/192621>\
**Category:** Rails\
**Created:** [August 3, 2010, 8:21am UTC](https://www.ruby-forum.com/t/adding-data-as-a-transaction/192621 "2010-08-03T08:21:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pipplo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b4bc9f/32.png) [@pipplo](https://www.ruby-forum.com/u/pipplo)\
**Post date:** [August 3, 2010, 8:21am UTC](https://www.ruby-forum.com/t/adding-data-as-a-transaction/192621/1 "2010-08-03T08:21:51Z")

</div>

Hey Everyone

I’m new to RoR and this group so please let me know if I’m not being  
descriptive enough, or if I’m asking questions when I should RTFM.

I have a basic understanding of RoR, but I’m kinda missing the next  
step for a web application I have in mind.

I want to create an order form, where the user clicks on say New Form,  
and then enter name and address and other basic info.

Then, using some AJAX he can add multiple “items” to the order. Now I  
think I understand how to do this if I want to create an Order, and  
then each time the user adds a new item that item gets put into the  
database, etc.

What I can’t figure out how to do is have the user fill out a form,  
and then submit it at the end to make sure nothing gets put into the  
db until the form is complete. I don’t want the user changing their  
mind before clicking submit and being left with stale data in the db.  
And I would also like to do it as a transaction so that if the  
database fails I can roll back data.

Now I’m sure this is possible…but I just don’t know where I’m  
supposed to store the data until final submission time in Ruby. In  
PHP I would just use some session data to store data as the user is  
going through. Is that the “Ruby Way” too? Am I missing something?

Any explanations, or pointers to some good reading are welcomed!

Thanks!

Joe

---

<div class="post-metadata">

**Author:** ![pipplo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b4bc9f/32.png) [@pipplo](https://www.ruby-forum.com/u/pipplo)\
**Post date:** [August 3, 2010, 2:27pm UTC](https://www.ruby-forum.com/t/adding-data-as-a-transaction/192621/2 "2010-08-03T14:27:44Z")

</div>

On 2 August 2010 22:48, pipplo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> database fails I can roll back data.
> 
> Now I’m sure this is possible…but I just don’t know where I’m  
> supposed to store the data until final submission time in Ruby. In  
> PHP I would just use some session data to store data as the user is  
> going through. Is that the “Ruby Way” too? Am I missing something?

Using the session is a reasonable way to go. I wonder whether you  
need to store anything in the db till all is complete, you could just  
keep it in the session. Then you don’t have to worry about clearing  
it up if the operation is never completed.

Colin
