# Making things DRY: RESTful address controller

**URL:** <https://www.ruby-forum.com/t/making-things-dry-restful-address-controller/160604>\
**Category:** Rails\
**Created:** [February 18, 2009, 3:53am UTC](https://www.ruby-forum.com/t/making-things-dry-restful-address-controller/160604 "2009-02-18T03:53:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [February 18, 2009, 3:53am UTC](https://www.ruby-forum.com/t/making-things-dry-restful-address-controller/160604/1 "2009-02-18T03:53:08Z")

</div>

Hello list,

I’m developing an e-commerce application, and the Checkout controller  
has an  
edit\_address and create\_addresses method. I’m not expert in any  
RESTful-based architecture (including the Rails implementation) but this  
just doesn’t feel right. I would rather have a Addresses controller to  
create and edit addresses, create a resource out of it, and nest it as  
needed for any other resource that needs it (by making it polymorphic,  
something like this:  
[Insight: Medical Device Software Articles and Resources](http://www.pathf.com/blogs/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/)).

To edit an address, I would then just POST to  
[http://url/addresses/idinstead](http://url/addresses/idinstead) of POSTing to checkout/edit\_address/.  
Much simpler and **DRY**.  
Would also clean up the checkout controller, removing from it the  
responsibilities of editing addresses…

However, in one of the checkout steps, I need to create two addresses in  
only one request (billing and shipping addresses) - as there is a screen  
with two addresses forms so the user can input their addresses. These  
addresses need to be created in the account (account has one billing  
address  
and has one shipping address). I would rather not create an  
edit\_addresses  
action in the addresses polymorphic controller, but I see no other way  
of  
receiving the input of this form and updating both addresses at the same  
time.

What do you think?

Thanks,

Marcelo.
