On Thu, Jan 21, 2010 at 9:33 AM, Andrew Edwards
<[email protected]> wrote:
> I'm struggling to see the natural solution to this with a nod to
> resources and keeping things restful.
>
> The problem is based around a Customer model with a fairly standard
> resource based controller (new, create, edit...)
>
> The registration is really a two step process:
>
> 1. First enter a postcode/zip and then search national database of
> addresses to offer selection of possible addresses for this postcode/
> zip in a select box.
>
> 2. User then selects an address and proceeds to what is essentially
> the /customers/new action with the address fields already populated,
> just requiring customer name and contact details to be filled in.
>
> I don't really want the new Customer object created until the final
> stage of name and contact details entry.
>
> My solution:
>
> I was thinking maybe a NewCustomerAddress resource with the 'index'
> action presenting the postcode/zip search box which submits to the
> 'new' action which looks up the submited postcode and renders
> available addresses in a select box.
>
> The user then selects the suitable address and submits the form, which
> requests the Customer 'new' action. Before rendering customer/new it
> adds the address detail to the new Customer object to be displayed in
> the form (user may then also tweak address if neccessary).
>
> Am I using resources correctly regarding the NewCustomerAddress? Could
> it be bundled in to the Customer resource?
>
> Thanks, Andrew.
>

That's pretty close to what I have done in similar situations.
Speaking from a rails point of view, I have found that whenever I need
to add more than the 7 basic actions or need to create an object with
a multi-step process, that it is time to break the functionality out
into more than one controller (i.e. resource).  This has really helped
to keep my code clean.

The only difference I would have to what you did is instead of making
the capturing of the zip code the "index" action of the
NewCustomerAddress controller, I would make it a "new" and a "action".
 The "new" action would show the form to capture the zipcode and the
"create" action would redirect and pass the value to the customer
controller's "new" action.

Also, I would probably rename the NewCustomerAddress resource to
something like CustomerAddressZip or ZipCodeSearch.

Other than that I think you are on the right track.  The main point is
to not try to shoe-horn in all your actions into one controller.  Keep
each controller to the basic seven.  When you find yourself needing
more actions, it is time to create a new controller.

Jamey
-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to