# Best way to keep DRY

**URL:** <https://www.ruby-forum.com/t/best-way-to-keep-dry/156392>\
**Category:** Rails\
**Created:** [December 26, 2008, 2:46pm UTC](https://www.ruby-forum.com/t/best-way-to-keep-dry/156392 "2008-12-26T14:46:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Franz\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecb155/32.png) [@Franz\_S](https://www.ruby-forum.com/u/Franz_S)\
**Post date:** [December 26, 2008, 2:46pm UTC](https://www.ruby-forum.com/t/best-way-to-keep-dry/156392/1 "2008-12-26T14:46:44Z")

</div>

Hello folks,

I have models called Address and Cart and both have their needed  
RESTful actions in place. Now there’s a third model called Despatch  
which assigns the Cart’s contents to a chosen Address.

Ideally then, to keep DRY, I’d like to rely on my Address and Cart  
controllers for:

1. choosing an Address as a recipient
2. displaying the Cart and allowing the user to make any modifications  
to its contents

before having my Despatch controller create the despatch.

My plan is to:

1. have the Despatch controller set a session variable to indicate that  
a despatch is being done

2. have the Address and Cart actions check that variable and alter  
their displays accordingly, ie Address index will display a select as  
recipient  
link in addition to the usual CRUD links.

3. have each step in the process point to my Despatch controller’s  
new action, with a params variable to indicate which step the user is  
at, ie choosing recipient (redirect\_to addresses\_path), modifying cart  
(redirect\_to cart\_path).

4. the last step will then be a link to Despatch’s create action, which  
will create the Despatch, empty the Cart and clear the session variable.

Does anyone know of a cleaner way of pulling this off?

Thanks in advance.

Franz
