Forum: Ruby on Rails When to make a new controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Randal S. (Guest)
on 2006-05-02 00:51
Hey all,

Ok this is probably a newb question, but I haven't been programming with
MVC for very long, and I've been wondering what the general opinion is,
or best practices, for making a new controller.  Like what cases would
you need a new controller for and what cases can you just put everything
into one controller?

Thanks in advance,
Randal
Ilan B. (Guest)
on 2006-05-02 00:57
Randal,

It really depends on your preferences.. I tend to design controllers
around "units of functionality".  I find that if I have one controller
juggling too many models, the code becomes cluttered..

For example, I could end up with a blogging controller that has list(),
list_articles() when it could be simply split up amongst 2 controllers:
controller1.list(), controller2.list(). The added benefit is that it's
much easier to work with the scaffolding than to fight it.. :)

Please be advised that I am not an expert in this area

ilan

Randal S. wrote:
> Hey all,
>
> Ok this is probably a newb question, but I haven't been programming with
> MVC for very long, and I've been wondering what the general opinion is,
> or best practices, for making a new controller.  Like what cases would
> you need a new controller for and what cases can you just put everything
> into one controller?
>
> Thanks in advance,
> Randal
Mick S. (Guest)
on 2006-05-02 00:58
If you're just starting out, keep it simple and create a separate
controller for each use case in your application.

Randal S. wrote:
> Hey all,
>
> Ok this is probably a newb question, but I haven't been programming with
> MVC for very long, and I've been wondering what the general opinion is,
> or best practices, for making a new controller.  Like what cases would
> you need a new controller for and what cases can you just put everything
> into one controller?
>
> Thanks in advance,
> Randal
Randal S. (Guest)
on 2006-05-02 05:54
Thanks guys.  I'll keep that in mind!

Mick S. wrote:
> If you're just starting out, keep it simple and create a separate
> controller for each use case in your application.
>
> Randal S. wrote:
>> Hey all,
>>
>> Ok this is probably a newb question, but I haven't been programming with
>> MVC for very long, and I've been wondering what the general opinion is,
>> or best practices, for making a new controller.  Like what cases would
>> you need a new controller for and what cases can you just put everything
>> into one controller?
>>
>> Thanks in advance,
>> Randal
Brian H. (Guest)
on 2006-05-03 20:58
(Received via mailing list)
Be careful here... you don't want to confuse controller's with their
actions. Controllers are a way to group user-focused functionality,
but unless you are designing extremely broad use cases, each of your
apps controllers will likely impact far more than a single use case.

Since people like to use the "blog app" example, I would recommend
downloading the Typo source code and looking at how the Controllers
and Models are laid out in there. It's a pretty good balance, with
probably a few more controllers than is actually needed (not counting
the admin stuff, since admin interfaces are very different from user
interfaces), but still a very good organization example.

-Brian
This topic is locked and can not be replied to.