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 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?
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)
- providers (this is a folder too)
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 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?
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
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.
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.
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!
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
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 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?
exactly what I needed. Thanks a lot!