# Grouping controllers

**URL:** <https://www.ruby-forum.com/t/grouping-controllers/61670>\
**Category:** Rails\
**Created:** [May 26, 2006, 12:42am UTC](https://www.ruby-forum.com/t/grouping-controllers/61670 "2006-05-26T00:42:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naju\_Ventura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Naju\_Ventura](https://www.ruby-forum.com/u/Naju_Ventura)\
**Post date:** [May 26, 2006, 12:42am UTC](https://www.ruby-forum.com/t/grouping-controllers/61670/1 "2006-05-26T00:42:30Z")

</div>

I’m grouping controllers to avoid cluttering the top-level namespace.

First, I used script/generate Admin::Customers new edit show list and  
then I  
used  
script/generate Admin::Providers new edit show list.

The generator created the subfolders correctly: I have an admin folder  
and  
inside there’s customer\_controller.rb and provider\_controller.rb.

I have the same structure in views. BUT when I go to  
[http://localhost:3004/admin/customer/list](http://localhost:3004/admin/customer/list) I get an Unknown Action error.  
I’m  
positive that the action is declared in the respective controller. Am I  
missing something?

I read about this on the Agile Web D. with Rails book on the  
Naming  
conventions section but can’t seem to make it work. Can anyone please  
advice?

---

<div class="post-metadata">

**Author:** ![Naju\_Ventura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Naju\_Ventura](https://www.ruby-forum.com/u/Naju_Ventura)\
**Post date:** [May 26, 2006, 1:52am UTC](https://www.ruby-forum.com/t/grouping-controllers/61670/2 "2006-05-26T01:52:01Z")

</div>

Hello,

Are you sure you have the following structure?

- app
  - controllers
    - admin
      - customers\_controller.rb
      - providers\_controller.rb  
…

- views
  - admin
    - customers (pay attention: this is a folder)
      - list.rhtml
      - …

    - providers (this is a folder too)
      - list.rhtml
      - …

Marcia

Naju Ventura wrote:

> I’m grouping controllers to avoid cluttering the top-level namespace.
> 
> First, I used script/generate Admin::Customers new edit show list and  
> then I  
> used  
> script/generate Admin::Providers new edit show list.
> 
> The generator created the subfolders correctly: I have an admin folder  
> and  
> inside there’s customer\_controller.rb and provider\_controller.rb.
> 
> I have the same structure in views. BUT when I go to  
> [http://localhost:3004/admin/customer/list](http://localhost:3004/admin/customer/list) I get an Unknown Action error.  
> I’m  
> positive that the action is declared in the respective controller. Am I  
> missing something?
> 
> I read about this on the Agile Web D. with Rails book on the  
> Naming  
> conventions section but can’t seem to make it work. Can anyone please  
> advice?

---

<div class="post-metadata">

**Author:** ![Naju\_Ventura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Naju\_Ventura](https://www.ruby-forum.com/u/Naju_Ventura)\
**Post date:** [May 26, 2006, 2:11am UTC](https://www.ruby-forum.com/t/grouping-controllers/61670/3 "2006-05-26T02:11:56Z")

</div>

Yes, I’m sure and yes, those are folders.

I also checked that my controllers start with:

class Admin::CustomerController \< ApplicationController

I’ve found this: [Implementing URLs with more than 3 levels in Rails - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/65539)  
it says that I should be using the following code inside  
CustomerController.rb

module Admin  
class CustomerController \< ApplicationController  
…  
end  
end

I tried that and still no results.

I’ve also read that perhaps I could solve this configuring routes.rb but  
I  
feel that shouldn’t be necessary.

What I find puzzling is that I’m not getting a “Routing  
error” but a “Unknown  
action” which I think it means that the route it’s trying to solve is  
correct. I think I’m mising something.

---

<div class="post-metadata">

**Author:** ![Naju\_Ventura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Naju\_Ventura](https://www.ruby-forum.com/u/Naju_Ventura)\
**Post date:** [May 26, 2006, 10:17am UTC](https://www.ruby-forum.com/t/grouping-controllers/61670/4 "2006-05-26T10:17:02Z")

</div>

Do you have admin\_controller.rb file in app/controllers folder? If yes,  
remove it or rename it (i.e. admin\_base\_controller.rb) if you need it  
i.e. for inheritance and it should work.

---

<div class="post-metadata">

**Author:** ![Naju\_Ventura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Naju\_Ventura](https://www.ruby-forum.com/u/Naju_Ventura)\
**Post date:** [May 26, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/grouping-controllers/61670/5 "2006-05-26T19:15:19Z")

</div>

indeed that’s the solution. I thought I needed to have  
admin\_controller.rb  
so the others could “inherit” from it. ☹

Can’t believe it was so simple! Thanks a lot szymek!

---

<div class="post-metadata">

**Author:** ![Naju\_Ventura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Naju\_Ventura](https://www.ruby-forum.com/u/Naju_Ventura)\
**Post date:** [May 26, 2006, 8:17pm UTC](https://www.ruby-forum.com/t/grouping-controllers/61670/6 "2006-05-26T20:17:27Z")

</div>

Naju Ventura wrote:

> Now I have a follow up question:
> 
> In the layouts, I had to create an admin folder and inside I created 2  
> layouts, customers.rhtml and providers.rhtml. Is there a way to have  
> ONLY one layout for customers\_controller.rb and providers\_controller.rb  
> ???

in your controller  
layout “layouts/customers”

something like that??

[http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html](http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html)

---

<div class="post-metadata">

**Author:** ![Naju\_Ventura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Naju\_Ventura](https://www.ruby-forum.com/u/Naju_Ventura)\
**Post date:** [May 26, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/grouping-controllers/61670/7 "2006-05-26T19:26:53Z")

</div>

Now I have a follow up question:

In the layouts, I had to create an admin folder and inside I created 2  
layouts, customers.rhtml and providers.rhtml. Is there a way to have  
ONLY one layout for customers\_controller.rb and providers\_controller.rb  
???

Naju Ventura wrote:

> I’m grouping controllers to avoid cluttering the top-level namespace.
> 
> First, I used script/generate Admin::Customers new edit show list and  
> then I  
> used  
> script/generate Admin::Providers new edit show list.
> 
> The generator created the subfolders correctly: I have an admin folder  
> and  
> inside there’s customer\_controller.rb and provider\_controller.rb.
> 
> I have the same structure in views. BUT when I go to  
> [http://localhost:3004/admin/customer/list](http://localhost:3004/admin/customer/list) I get an Unknown Action error.  
> I’m  
> positive that the action is declared in the respective controller. Am I  
> missing something?
> 
> I read about this on the Agile Web D. with Rails book on the  
> Naming  
> conventions section but can’t seem to make it work. Can anyone please  
> advice?

---

<div class="post-metadata">

**Author:** ![Naju\_Ventura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Naju\_Ventura](https://www.ruby-forum.com/u/Naju_Ventura)\
**Post date:** [May 26, 2006, 8:26pm UTC](https://www.ruby-forum.com/t/grouping-controllers/61670/8 "2006-05-26T20:26:24Z")

</div>

exactly what I needed. Thanks a lot!
