# Separate controller for side-bar components?

**URL:** <https://www.ruby-forum.com/t/separate-controller-for-side-bar-components/163770>\
**Category:** Rails\
**Created:** [March 24, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/separate-controller-for-side-bar-components/163770 "2009-03-24T19:04:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ressister](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@ressister](https://www.ruby-forum.com/u/ressister)\
**Post date:** [March 24, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/separate-controller-for-side-bar-components/163770/1 "2009-03-24T19:04:53Z")

</div>

I’m in the process of refactoring an existing Rails app and am  
wondering - is it common practice to have a controller for each model  
that has CRUD actions? For instance, in my app I have a side bar  
where users can add diary entries to a side-bar, highlighting them in  
bulletin-board fashion within their diary. This bulletin board will  
only live inside the diary. Should it have its own controller then?

What’s the general rule. I’ve been reading The Rails Way, and it  
seems that it should, which would also allow me to create a nested  
resource for this as well which would allow for some out-of-the-box  
routing if I were ever to surface this component somewhere else.

I look forward to your thoughts, and thanks!

-A

---

<div class="post-metadata">

**Author:** ![ressister](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@ressister](https://www.ruby-forum.com/u/ressister)\
**Post date:** [March 24, 2009, 7:10pm UTC](https://www.ruby-forum.com/t/separate-controller-for-side-bar-components/163770/2 "2009-03-24T19:10:47Z")

</div>

On Tue, Mar 24, 2009 at 1:03 PM, ressister [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m in the process of refactoring an existing Rails app and am  
> wondering - is it common practice to have a controller for each model  
> that has CRUD actions? For instance, in my app I have a side bar  
> where users can add diary entries to a side-bar, highlighting them in  
> bulletin-board fashion within their diary. This bulletin board will  
> only live inside the diary. Should it have its own controller then?

It’s up to you how to separate things, there’s no limit on how many or  
how few controllers you can or have to have.

> What’s the general rule. I’ve been reading The Rails Way, and it  
> seems that it should, which would also allow me to create a nested  
> resource for this as well which would allow for some out-of-the-box  
> routing if I were ever to surface this component somewhere else.
> 
> I look forward to your thoughts, and thanks!

I split things up as much as I can at the start, makes growing the app  
easier later. You might consider putting things that require  
authentication in separate controllers than one that don’t for  
example.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![ressister](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@ressister](https://www.ruby-forum.com/u/ressister)\
**Post date:** [March 24, 2009, 8:11pm UTC](https://www.ruby-forum.com/t/separate-controller-for-side-bar-components/163770/3 "2009-03-24T20:11:38Z")

</div>

Thanks for the response Donald. I started in just the opposite  
direction - with only a couple core controllers. I wasn’t sure if it  
was common to have a controller for each model in your app? Perhaps  
that’s the guiding principle, and you make judgements based on that.

I like your suggestion of splitting based on Authenticated versus  
public. I’m already doing that for the most part, so perhaps I will  
add a few more controllers for authenticated models/views to make the  
app more CRUD compliant.

Let me know if you have any other thoughts and thanks again for your  
response.

-A
