# Carrying model date from one page to the next

**URL:** <https://www.ruby-forum.com/t/carrying-model-date-from-one-page-to-the-next/99076>\
**Category:** Rails\
**Created:** [July 20, 2006, 4:54am UTC](https://www.ruby-forum.com/t/carrying-model-date-from-one-page-to-the-next/99076 "2006-07-20T04:54:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geoffrey\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8e7dd6/32.png) [@Geoffrey\_L](https://www.ruby-forum.com/u/Geoffrey_L)\
**Post date:** [July 20, 2006, 4:54am UTC](https://www.ruby-forum.com/t/carrying-model-date-from-one-page-to-the-next/99076/1 "2006-07-20T04:54:14Z")

</div>

I am working on a crude first-go-round-in-rails shopping cart and  
can’t figure out for the life of me the best way to do this. I have a  
shopping cart that has one page during the checkout that handles the  
address information, then the next handles the actual credit card  
information. How do I take the information from the address form and  
keep it alive long enough to put it in to the cart and then database  
once the order is accepted?

One scenario I thought of is to store the customer address  
information in the database and just link the order to the customer  
in the database. The only problem with that is if I save the address  
info into the db before the order is completed, I have the  
possibility of a ton of unused addresses in the database.

Is there a way to hold off on a database save for a page? If that  
happens, can I keep the validation from the model working on the  
first page (ie without a save)?

Thanks for any help.  
-geoffrey

---

<div class="post-metadata">

**Author:** ![Geoffrey\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8e7dd6/32.png) [@Geoffrey\_L](https://www.ruby-forum.com/u/Geoffrey_L)\
**Post date:** [July 20, 2006, 5:53am UTC](https://www.ruby-forum.com/t/carrying-model-date-from-one-page-to-the-next/99076/2 "2006-07-20T05:53:06Z")

</div>

The order will be accepted once the credit card is accepted/processed.

Your first scenario sounds right to me as well, I guess I just don’t  
know how to do sessions well (or at all). =) I have a cart session  
working because of the Depot app in Agile Web D. With Ruby  
On Rails. Could you help steer me in the right direction?

For example, would I create a model for an Address, then load that  
object into the already-created cart session? How would validation  
work for form data just coming from a session? I’m assuming I would  
have to write my own, correct? When I try to use  
validates\_presence\_of, it gives me the error that the class isn’t a  
subclass of ActiveRecord, which is correct because it isn’t getting  
written into the database, right?

I agree about the user login scenario, but that’s not what the client  
is asking for. If it were mine, I’d do it in a heartbeat.

Thanks for your help!  
-geoffrey

---

<div class="post-metadata">

**Author:** ![Geoffrey\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8e7dd6/32.png) [@Geoffrey\_L](https://www.ruby-forum.com/u/Geoffrey_L)\
**Post date:** [July 20, 2006, 5:06am UTC](https://www.ruby-forum.com/t/carrying-model-date-from-one-page-to-the-next/99076/3 "2006-07-20T05:06:39Z")

</div>

Will the order be accepted instantly? (after the credit card is  
processed)  
Or do you not want an order to be processed until the store owner  
accepts the order?

If it’s the first then you can simply store the address information in  
a session since the credit card processing should not take so long  
that the session will get erased.

If it’s the second, I would store the information in the database  
anyways and just purge it every week or so. (You write a ruby script  
that deletes all the addresses that will never be processed to clean  
the database so that way you don’t have so many unused addresses.)

A third way to do it would just be to force every customer to have an  
account with you and store the address along with their account. That  
would be my way of doing it because you can do a lot more powerful  
things with the website if you have accounts for users.

If I’m misunderstanding you, let me know and explain your scenario a  
bit better and I’ll to my best to help you out.

Hope this helps,  
Rick Martinez

On 7/19/06, Geoffrey L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> in the database. The only problem with that is if I save the address  
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Rick Martinez  
Director of Technology  
Complexity Gaming
