# Refactoring controllers vs. actions

**URL:** <https://www.ruby-forum.com/t/refactoring-controllers-vs-actions/104757>\
**Category:** Rails\
**Created:** [May 22, 2007, 5:19am UTC](https://www.ruby-forum.com/t/refactoring-controllers-vs-actions/104757 "2007-05-22T05:19:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spdemac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@spdemac](https://www.ruby-forum.com/u/spdemac)\
**Post date:** [May 22, 2007, 5:19am UTC](https://www.ruby-forum.com/t/refactoring-controllers-vs-actions/104757/1 "2007-05-22T05:19:33Z")

</div>

I just completed an exercise of breaking down an existing project and  
mapping out the controllers and actions, then re-factoring them into  
some perhaps more RESTful. Though I could be wrong since I am still  
grasping REST.

Most of the controllers mapped perfectly into a REST structure, except  
for a few.

I have Messages, which can respond to all the usual actions, plus a few  
more. The extras are Assign, Transfer, Escalate and Redirect.

My inclination is to simply add the actions to the Message controller,  
then map the resources as needed.

Is that the best practice?

---

<div class="post-metadata">

**Author:** ![spdemac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@spdemac](https://www.ruby-forum.com/u/spdemac)\
**Post date:** [May 22, 2007, 5:49am UTC](https://www.ruby-forum.com/t/refactoring-controllers-vs-actions/104757/2 "2007-05-22T05:49:53Z")

</div>

On May 21, 10:19 pm, Lon B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> My inclination is to simply add the actions to the Message controller,  
> then map the resources as needed.
> 
> Is that the best practice?
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

I found this video really great:

> **[RailsConf Keynote: David Heinemeier Hansson — ScribeMedia](https://www.scribemedia.org/dhh/)**
>
> We independently review everything we recommend. When you buy through our links, we may earn a commission. Read the full disclosure here. With the release of Rails 1.2, we take a look back at David Heinemeier Hansson’s RailsConf keynote from Chicago....

In there he says that roughly, not everything will map and don’t force  
it. But before he says that he gives two examples where he needed to  
rethink his objects and CRUD.

For example, with your assign. What are you assigning? Are you,  
instead, actually creating a relationship between two objects. If so,  
then use CRUD (and REST) to create and manage the relationship.

Also, it sounds like Transfer, Escalate, and Redirect are actually  
just special cases of update.

But, the main thing I took away from that video is a philosophy of not  
forcing anything.

---

<div class="post-metadata">

**Author:** ![spdemac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@spdemac](https://www.ruby-forum.com/u/spdemac)\
**Post date:** [May 22, 2007, 1:10pm UTC](https://www.ruby-forum.com/t/refactoring-controllers-vs-actions/104757/3 "2007-05-22T13:10:14Z")

</div>

pedz wrote:

> On May 21, 10:19 pm, Lon B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> I found this video really great:
> 
> [RailsConf Keynote: David Heinemeier Hansson — ScribeMedia](http://www.scribemedia.org/2006/07/09/dhh/)
> 
> In there he says that roughly, not everything will map and don’t force  
> it. But before he says that he gives two examples where he needed to  
> rethink his objects and CRUD.

Thanks. Listening to that talk did help clarify a few my my assumptions.
