Sven Magnus wrote:
So, is this approach any good?
As Russel notes, you need to recognize that some users may not have js
enabled and deal with that somehow. How you do it really depends on
business model. More on that below.
- Store the new “item” in a session variable
It’s early here and I don’t have a threaded email reader so I don’t know
there was something in your previous post that would drive storing the
in a session variable. The choice between storing items in session
variables and in the database depends on too many things to give advice
without more info.
- Create two diffferent forms on the same page, one for adding the
item and one for adding the subitems using Ajax
- The subitem form will add new subitems to the item stored in the
Is that how this kind of thing should/coul be done?
The general model would be to first render the main form for adding
That form could have an element on it that would trigger the rendering
the second form. So maybe there’s a checkbox labeled ‘add sub-items’
to an item on the main form. You put an observe_field on that checkbox.
your design thinking, you have to figure out how you’re going to handle
transaction in both js-enabled and js-disabled states. Here’s one,
If the user has js enabled, when they check the checkbox it will trigger
method in the controller which uses RJS to render the sub-form
So if they’ve got js-enabled they’ll go ahead and add sub-items before
submitting the main form. If the user doesn’t have js enabled, the
won’t do anything. When the main form is submitted, you check the value
the checkbox. If it’s checked, you check to see if you have any
If you do, you assume they have js-enabled, that they’re done with that,
take them to the next step in the process. If you don’t, you assume
have js-disabled and take them to an interim page where they can enter
The respond_to method can let you know very early in the user’s visit
whether or not they have js-enabled. This gives you the ability to plan
entirely different ‘routes’ through the app. Or you can take an
like the above. Or you can, depending on your business model, decide
allow the use of the site by js-disabled browsers. All, and more, are
choices. It’s important to make that decision explicitly so you can
communicate it if needed to your visitors.