Every controller has to be ended with _controller?

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

Good point, we don’t do blog_model so why do we have to do blogs_controller?

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

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:

Andreh Luis 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.

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.

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/
24364f3ed58bb77b?hl=en) I think the reasoning behind that change will
answer Andreh's question.

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,

    map.x /url :controller => 'foo'

means that the controller class is FooController

2) 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'

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

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

Thanks.