Forum: Ruby on Rails Best Practices for Multi-step Record Creation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D006ba456e634e2bf249b0d021000efc?d=identicon&s=25 Gavin Hughes (gavvin)
on 2009-01-13 03:09
(Received via mailing list)
class Activity
has_many :locations

In activities#new, I navigate away and select a location (among other
things) on a map.  At this point, the @activity is still missing
attributes and is invalid.  What is the best practice for preserving
the state of this invalid record until I return to it?  I could:

1. Make all validations conditional depending on the state of the
record.  But this seems pretty clunky.  I want to be able to call
#valid? and get the correct answer.

2. Create a supper class RawActivity with no validations and then let
Activity inherit from it when it's ready to be saved.  This also looks
like a messy solution.

3. Dump all the @activity attributes into the session, reconstitute
them in the Location controller.  Find the location, dump the
@location attributes into session.  Go back to the Activity controller
and stitch it all together.  Yuck.

4. Render the form in javascript and hide everything until it's ready
to be saved.

Am I missing something? What's the best practice?
This topic is locked and can not be replied to.