Carrying model date from one page to the next

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

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

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. [email protected] wrote:

in the database. The only problem with that is if I save the address
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rick Martinez
Director of Technology
Complexity Gaming

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs