# Controllers - model vs. use case centric

**URL:** <https://www.ruby-forum.com/t/controllers-model-vs-use-case-centric/97477>\
**Category:** Rails\
**Created:** [July 7, 2006, 11:03am UTC](https://www.ruby-forum.com/t/controllers-model-vs-use-case-centric/97477 "2006-07-07T11:03:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![reynar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@reynar](https://www.ruby-forum.com/u/reynar)\
**Post date:** [July 7, 2006, 11:03am UTC](https://www.ruby-forum.com/t/controllers-model-vs-use-case-centric/97477/1 "2006-07-07T11:03:16Z")

</div>

I am working on a reasonably large application (which happens to be my  
first with rails).

I was hoping to get some input on organisation of controllers and  
actions.

I am finding having used scaffolding more at the beginning my  
controllers tend to be very model centric, in that they mostly contain  
all the actions for management of that particular model, which may crash  
across multiple use cases. I find this effective in the sense it keeps  
related actions together. However I am wondering whether it makes more  
sense to split more administrative actions out into a separate  
controllers?

I imagine this could be a matter of style, experienced MVC developers  
mixing the two. However any comments on the people’s experience would be  
much appreciated.

* * *

I also have a question regarding menu pages, I have many maintenance  
actions that I wish to group into a section of the application. I was  
thinking of having something like DashboardController with actions such  
as ‘maintenance’, ‘warehouse’, ‘accounts’ etc. These would contain views  
with links to major controllers and actions specific to that area of  
work.

This seems reasonably ‘tidy’, however has anyone tackled it differently?

Thanks, Andrew.

---

<div class="post-metadata">

**Author:** ![reynar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@reynar](https://www.ruby-forum.com/u/reynar)\
**Post date:** [July 7, 2006, 4:21pm UTC](https://www.ruby-forum.com/t/controllers-model-vs-use-case-centric/97477/2 "2006-07-07T16:21:55Z")

</div>

I usually mix it up for relatively larger projects, with more preference  
to  
use case centric. When authentication and authorization is implemented,  
it’s  
much easier to put all related secure actions into one controller  
instead of  
having them scattered throughout the different unrelated ones. Still,  
this  
is based on instinct and I don’t have a formal decision process for it.  
I’d  
like to hear what others do too.

“Andrew E.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in  
message news:removed\_email\_address@domain.invalid…

---

<div class="post-metadata">

**Author:** ![reynar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@reynar](https://www.ruby-forum.com/u/reynar)\
**Post date:** [July 7, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/controllers-model-vs-use-case-centric/97477/3 "2006-07-07T18:36:13Z")

</div>

It seems that DHH is tackling this question, with his new proposal to  
orient everything around C/R/U/D.

There’s a fundamental ambiguity here: What does a controller do? The  
answer right now, in Rails, is: “not much”. It’s just a way of grouping  
a bunch of actions, for convenience. Although it’s technically called a  
class, it doesn’t have any of the class like things that normally make  
classes classes: invariants, shared private data / information hiding,  
encapsulation, single responsibility.

Hence, it’s really never clear the “right” place to put actions, and how  
to group controllers.

I think the Rails community would benefit from looking again at  
classical OO strategies. The responds\_to |wants| block/switch,  
despiting all the raving about it, is exactly the type of thing that  
inheritance was designed to avoid. As Rails matures, I think we have a  
lot to gain by using these techniques.

---

<div class="post-metadata">

**Author:** ![reynar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@reynar](https://www.ruby-forum.com/u/reynar)\
**Post date:** [July 8, 2006, 10:33am UTC](https://www.ruby-forum.com/t/controllers-model-vs-use-case-centric/97477/4 "2006-07-08T10:33:32Z")

</div>

Thanks for the replies.

I have started using smaller, model centric controllers to handle the  
basic CRUD for more simple models. On the more complicated models which  
often make use of the simpler models I favor a more use case centric  
approach to my controllers.

I’ve also spent some time thinking ahead as to potential number of use  
cases and it would be madness to not split functionality into modules,  
everything in a flat layout would be terrible to keep track of. This  
again works quite well with the above scenario.

Andrew.

---

<div class="post-metadata">

**Author:** ![reynar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@reynar](https://www.ruby-forum.com/u/reynar)\
**Post date:** [July 7, 2006, 11:26pm UTC](https://www.ruby-forum.com/t/controllers-model-vs-use-case-centric/97477/5 "2006-07-07T23:26:25Z")

</div>

We went through similar pains on our app. Eventually it became  
obvious with controllers linked to major areas of functionality in  
the system. for example, account management, team management, project  
management etc.

Another way to go though is to just resign to the fact that  
controllers are weak, OO wise, in Rails right now, so simply have one  
controller for each page. We started out that way and refactoring  
ended up leading us to a better model.

* * *

Peter Wright  
removed\_email\_address@domain.invalid

Personal Blog → [http://peterwright.blogspot.com](http://peterwright.blogspot.com)  
Agile Development Blog → [http://exceeding-expectations.blogspot.com](http://exceeding-expectations.blogspot.com)
