Forms. Specifically entering data, submitting, discovering validation error, redisplaying the form with user's entered data and error messages.
I know how I would approach it left to my own devices (described below), but wondering if there's an idiomatic Rails way.
The classic "How To" stuff shows setting values of form elements directly from models. Well, that's spiffy if nothing goes wrong, but in the above sequence of events, that approach doesn't work.
Normally, in the controller I would load the model with data, I would then create a form data object ("FDO") with a placeholder for each field that applies to the user-entered data in the form. I would populate the HTML input values with the contents of this FDO. So, value="<%= fdo.firstName %>" not value="<%= model.firstName %>"
To populate the FDO I test params to see if the form had already been submitted. If yes, I populate the FDO by copying values from params. If not, I populate the FDO by copying original data from the model.
This way the form sees virgin data from the database/model when the form is first displayed, and then the tainted data from user input if the form is redisplayed.
Does Rails have anything built in for this process, or is the developer left to implement his own system like I describe above (which of course is fine with me).
-- gw (www.railsdev.ws)