namespaced controller question

I have a utility controller that has an action in it. Before I changed to namespaced controllers, I could access the action with:

/utility/my_action

There are no resources associated with the controller, so I'm assuming the stock route

map.connect ':controller/:action/:id'

picked it up. However, for reasons I don't want to go into detail about, I moved the utility controller into a namespace (Web), and the route started failing. Ultimately, I added

map.connect 'web/utility/:action', :controller => 'web/utility'

to routes.rb and it started working again. I do not understand why I had to specify 'web/utility' in the map.connect statement. Why didn't the stock map.connect pick it up? And why wouldn't

map.connect 'web/:controller/:action'

work?

Thanks, Phillip

I have a utility controller that has an action in it. Before I changed to namespaced controllers, I could access the action with:

/utility/my_action

There are no resources associated with the controller, so I'm assuming the stock route

map.connect ':controller/:action/:id'

picked it up. However, for reasons I don't want to go into detail about, I moved the utility controller into a namespace (Web), and the route started failing. Ultimately, I added

map.connect 'web/utility/:action', :controller => 'web/utility'

to routes.rb and it started working again. I do not understand why I had to specify 'web/utility' in the map.connect statement. Why didn't the stock map.connect pick it up? And why wouldn't

map.connect 'web/:controller/:action'

work?

Craig White wrote:

picked it up. However, for reasons I don't want to go into detail about,

work?

---- assuming that the first line of app/controllers/web/utility_controller.rb looks like

class Web::UtilityController < ApplicationController

No, it's actually

class Web::UtilityController < Web::BaseController

where

class Web::BaseController < ApplicationController

I don't think you really need to do a whole lot with routes.rb at all

I didn't think so either. That's why I was surprised when the default route of

map.connect ':controller/:action/:id

didn't work. But since I'm not passing an id to this action, I even tried

map.connect ':controller/:action

but that didn't work either.

(the views would necessarily have to follow a similar pathing in app/views/web/utility)

Right. I got all that taken care of. I've had success in the past using namespaced controllers, but this is the first time I have done so with one that wasn't a resource. I've never had any difficulty when I have done this something like this in routes:

map.namespace :web do |web|   web.resources :pages end

I don't really want to resource this utility controller as it is just for actions that do little odds and ends that need to be done, but don't really belong anywhere else. The particular case in question is storing the current state of an expandable menu structure. As the user navigates from page to page, I restore the menu to the "current" state so the user doesn't have to keep expanding things over and over. It's stored in the session, not the database, so I didn't want to put it on the People (user) controller.

but I also wonder whether you are using the plural utilities instead of the singular utility, etc.

No, just singular. Since it's not a resource, it makes more sense to me to have it singular. Much like HomeController.

Thanks for your input!

Peace.

The only thing I've noticed with namespaced controllers like that and the :controller/:action/:id default route is that a restart seems to be required to pick up new controllers.

Fred

Frederick Cheung wrote: