# Every controller has to be ended with \_controller?

**URL:** <https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345>\
**Category:** Rails\
**Created:** [February 6, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345 "2008-02-06T23:06:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 6, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/1 "2008-02-06T23:06:01Z")

</div>

Hi there,

I’m thinking here about this, if the controller are located inside the  
controllers folder, why should we name them with \_controller at the end?

it’ll screw with the routing system if we get the ‘\_controller’ out.

Is there any case I put some .rb on the controllers folder without being  
a controller? because from my point of view, if a controller ir located  
inside the controllers folder, it should be a controller.

So, what do you think? I was just studying rails source and this  
question came to my mind. Maybe it’s just nonsense, but i think that not  
totally.

Thanks,

AndrÃ© Luis

---

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 6, 2008, 11:47pm UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/2 "2008-02-06T23:47:20Z")

</div>

Good point, we don’t do blog\_model so why do we have to do  
blogs\_controller?

On Feb 7, 2008 8:36 AM, Andreh L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## a controller? because from my point of view, if a controller ir located AndrÃ© Luis
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 7, 2008, 12:36am UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/3 "2008-02-07T00:36:11Z")

</div>

personally, i dislike multiple files with the same name in a project  
(ie: app/controllers/blog.rb and app/models/blog.rb) Some tabbed  
editor IDEs dont include paths in the tabs, which could make it  
somewhat confusing

---

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 7, 2008, 12:57am UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/4 "2008-02-07T00:57:21Z")

</div>

That’s not the case, I mean, you are forced to use \_controller.

Yes, files with the same name sounds confusing.  
But it is redundant to call \_controller, when you are inside of the  
controller’s folder, like Ryan said, we don’t have a blog\_model.

I think that the controllers’ names should be more flexible.  
it’s just my what I’m thinking, of course we can find a lot reasons to  
let the \_controller stay.

All the .rb on the controllers folder are controllers anyway.

Reacher wrote:

> personally, i dislike multiple files with the same name in a project  
> (ie: app/controllers/blog.rb and app/models/blog.rb) Some tabbed  
> editor IDEs dont include paths in the tabs, which could make it  
> somewhat confusing

---

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 7, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/5 "2008-02-07T12:30:12Z")

</div>

Andreh L. wrote:

> That’s not the case, I mean, you are forced to use \_controller.
> 
> Yes, files with the same name sounds confusing.  
> But it is redundant to call \_controller, when you are inside of the  
> controller’s folder, like Ryan said, we don’t have a blog\_model.
> 
> I think that the controllers’ names should be more flexible.  
> it’s just my what I’m thinking, of course we can find a lot reasons to  
> let the \_controller stay.
> 
> All the .rb on the controllers folder are controllers anyway.
> 
> Reacher wrote:
> 
> > personally, i dislike multiple files with the same name in a project  
> > (ie: app/controllers/blog.rb and app/models/blog.rb) Some tabbed  
> > editor IDEs dont include paths in the tabs, which could make it  
> > somewhat confusing

I believe its a namespace issue, can’t have multiple classes with the  
the same name. Just a guess.

---

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 7, 2008, 1:50pm UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/6 "2008-02-07T13:50:28Z")

</div>

## It wouldn’t BE with the same name if people named their controllers correctly! It’s not blog\_controller, its blogs\_controller. Meaning the class would be Blogs and not Blog! I’m all for this idea.

Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 7, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/7 "2008-02-07T17:02:33Z")

</div>

On 2/7/08, Russ J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I believe its a namespace issue, can’t have multiple classes with the  
> the same name. Just a guess.

Not in the same module/class, and since models, and controllers. are  
in the outermost ruby namespace, they have to have different names.

but there’s a further reason, I think. Or actually two.

1. Rails uses the convention of mapping names in context, so, for  
example in a routes.rb,

means that the controller class is FooController

1. Rails autoloading. Note that Rails doesn’t require you to use  
‘require’ to load code. When FooController is mentioned in running  
code, and it hasn’t been loaded, rails catches the exception raised by  
the missing constant and looks for the code by searching for a fill in  
one of the directories on the load path named ‘foo\_controller.rb’

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 7, 2008, 2:38pm UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/8 "2008-02-07T14:38:58Z")

</div>

I’ll second the idea that it is a namespace issue. That would also  
explain why we have blog\_helper and blog\_test and blog\_spec in their  
respective folders.

On this note though, how dose everyone feel about the talk in the core  
to move application.rb to application\_controller.rb? (http://  
[groups.google.com/group/rubyonrails-core/browse\_thread/thread/](http://groups.google.com/group/rubyonrails-core/browse_thread/thread/)  
24364f3ed58bb77b?hl=en) I think the reasoning behind that change will  
answer Andreh’s question.

---

<div class="post-metadata">

**Author:** ![andreh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@andreh](https://www.ruby-forum.com/u/andreh)\
**Post date:** [February 7, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/every-controller-has-to-be-ended-with-controller/128345/9 "2008-02-07T17:32:22Z")

</div>

yes, if you take a look at routing.rb at rails source you’ll see that  
it searches for all .rb files in the controller directory that ends with  
\_controller.rb.

What I had in mind when I post this topic was that I was forced to use  
the \_controller at the end, even knowing that all the .rb files located  
there would be controllers. Knowing that all the files there are  
controllers, why put the controller?

Ok, using the \_controller is a good thing to maintain control of the  
Controllers, and I agree with that. and keep about namespace too, having  
many files with ‘same’ names isn’t good. It could be a mess.

about application.rb, I asked myself why application hasn’t the  
\_controller at the end. I think that is take all the \_controllers out,  
or put the \_controller at every controller, even application.

following the talk in rails core, I found this ticket  
[http://dev.rubyonrails.org/ticket/10570](http://dev.rubyonrails.org/ticket/10570)

about application.rb not following tha name convention, and it’s  
consequences.

Thanks.
