How do CRUD and REST work for a wizard-style application

Daniel Jilg wrote:

Second thing: The problem with standard actions. That should be possible
if you dont actually save the data to the database as long as the wizard
is running, but into a session instead. Then, when the user has entered

What on earth is wrong with saving to the database? If you model
correctly you will have a Script and Submitted Script. Why shouldn't a
user be able to come back to a partially completed script tomorrow?

The session system is merely there to provide an illusion of state
between what are actually unconnected HTTP requests to various
webservers. It should really be nothing more than a bunch of pointers
to stuff *stored in the database*.

Because validations on models assume the model is complete. If you
have "validates_presence_of :foo", when :foo isn't going to be filled
out until some later page in your multi-page-wizard form, you CAN'T
save the model using AR before that page.

Not true. Validations are optional. You can save without validating, or you can validate conditionally. From the API:

validates_presence_of :foo, :if => { |user|
user.signup_step > 2 })

Validations have default behaviors, but that does not mean that you cannot do more. One might consider a different approach to modeling records for multi-step processes. Just don’t let the way you think Rails works dictate how you model your application.

Fair enough; I hadn't looked at them closely enough to have seen that.
Thanks for that information, Brian.


The more I think about this, the less I like it. What if my model
participates in a number of different flows/wizards? I'll need to
have a Proc that tests 1 of n conditions? No thanks.
I want to be able to tell /save/ to validate or not, not the model.
This way ties the model to the controller.

I guess I can have an attribute on the model that determines if
validation should occur, and set that before calling save, but that
feels... wrong.

I'm probably missing something basic here; what is it?

Michael Campbell wrote:

I'm probably missing something basic here; what is it?

Your model is trying to do two things at once. You have a completed
script and a script. Those are two different states of a model object,
and the model should reflect that - two model classes and an
inheritance hierarchy.


Interesting; I'll ponder that and see if it fits better what I'm
doing. Thanks for that insight, Neil.