# Namespaced routing + AJAX issues

**URL:** <https://www.ruby-forum.com/t/namespaced-routing-ajax-issues/137040>\
**Category:** Rails\
**Created:** [May 8, 2008, 2:31pm UTC](https://www.ruby-forum.com/t/namespaced-routing-ajax-issues/137040 "2008-05-08T14:31:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [May 8, 2008, 2:31pm UTC](https://www.ruby-forum.com/t/namespaced-routing-ajax-issues/137040/1 "2008-05-08T14:31:48Z")

</div>

Hi Im a newbie so please bear with me.

I’ve two controllers admin and public.

The admin controller inherits from the public controller.

I have two problems

The controller returns method admin\_admin\_hierarchies\_path not found. If  
I remove the redirect\_to {[:admin, hierarchies]} and make it  
{hierarchies} I can get it to work, but the return from the ajax call  
tries to access the new method of the public hierarchies controller, and  
since there isn’t a method for that in the new controller it fails.

undefined method `admin\_admin\_hierarchies\_url’ for  
#Admin::HierarchiesController:0x47f90f0

app/controllers/admin/hierarchies\_controller.rb:13:in `new' app/controllers/admin/hierarchies_controller.rb:12:in`new’

routes.rb

ActionController::Routing::Routes.draw do |map|  
map.resources :hierarchies

map.root :controller =\> ‘sessions’  
map.resources :sessions  
map.resource :session, :controller =\> ‘sessions’  
map.login ‘/login’, :controller =\> ‘sessions’, :action =\> ‘new’  
map.logout ‘/logout’, :controller =\> ‘sessions’, :action =\> ‘destroy’  
map.namespace(:admin) do |admin|  
admin.resources :hierarchies  
end

map.connect ‘:controller/:action/:id.:format’  
map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:sort/:order’  
end

class Admin::HierarchiesController \< HierarchiesController

layout ‘admin’  
skip\_before\_filter :login\_required  
before\_filter :admin\_required, :except =\> [:filterhierarchies]

# GET /admin\_hierarchies/new

# GET /admin\_hierarchies/new.xml

def new  
@hierarchy = Admin::Hierarchy.new  
@hierarchy\_company = Company.find(:all, :order =\> “id”)  
respond\_to do |format|  
format.html { redirect\_to([:admin,@hierarchy]) }  
format.xml { render :xml =\> @hierarchy }  
end  
end  
def filterhierarchies  
respond\_to do |want|  
@co\_business\_streams = BusinessStream.search(params[:company\_id])  
want.js{  
render :update do |page|  
page.replace\_html ‘hierarchy\_business\_stream\_id’, :partial =\>  
‘filterhierarchies’  
end  
}  
end  
end
