admin namespace

hi,

just added this to my routes:

map.namespace :admin do |admin|
admin.resources :categories
end

to have a /admin/… urls.

but now all of my other links do have that prefix!? why is that?
any ideas?

thx

You just added categories to your admin resource. That said, you'll end
up with routes looking like this /admin/id/resource.

What that means is that any time you need to call a resource, you'll
have to include the admin id in it as they as "nested".

You could have a look at this railscast
http://railscasts.com/episodes/139-nested-resources

Luis

http://www.saffie.ca

thx luis,

i know what u are describing. what i didnt know and dont know how to “undo” is:

being on a regular resource, eg index-view of projects, all urls show fine, eg :3000/tasks, 3000/milestones, …

but being on the admin/categories resource and i hover over the “link_to projects” and all the others, it shows me /admin/projects. i didnt specify that, so im just wondering …

thx

Can you post your link_to code?

If you have something like
link_to projects_path

it shouldn't pick the the route from admin

thats exaclty why im gettin confused. here are two link from the application.rhtml:

<%= link_to “Invite Friends”, :controller=>‘tellyourfriends’, :action=>‘new’ if logged_in? %>
<%= link_to_unless_current ‘Browse Categories’, :controller=>‘categories’, :action=>‘index’

here the routes:
map.namespace :admin do |admin|
admin.resources :categories
end
map.resources :categories

is there somethign wrong here?

thx for ur time! i appreciate it

tom

You're defining categories as a single resource and nested resource.
That's why you're getting the conflicting results.

Which one of the two links are is displaying the nested url? I assume
the second one

Luis

well,

i was following a tutorial regarding admin namespaces. i do have a model holding categories. goeal would be to have a user-ui to have just 3000/categories and an admin-ui for editing etc.
not sure now how to proceed. i would like to keep the admin views in a separate folder plus admin-controller.

do u have a pointer?

thx

im not sure if you need a nested resource for what you want to
accomplish.
Just go ahead and define admin and categories as a single resource.

Luis

Looking at the documentation more closely, you could do something like
this in your routes

namespace "admin" do
  resources :categories
end

This will give you /admin/categories in the way you want.

http://guides.rubyonrails.org/routing.html

Luis

yes, was looking at the same, but that is rails3 if im not wrong.

ill keep digging

thx

doing just:
map.namespace :admin do |admin|

admin.resources :categories, :controller=>"categories"

end

gives me two routes:
/admin/categories
/categories

both are hitting the right controllers, but once im on the admin-index-view, all other links are still prefixed with admin. o well

type rake routes to figure out all the new routes

Tom Tom wrote in post #956151:

doing just:
map.namespace :admin do |admin|

    admin.resources :categories, :controller=>"categories"
end

gives me two routes:
/admin/categories
/categories

both are hitting the right controllers, but once im on the
admin-index-view,
all other links are still prefixed with admin. o well

You may need to use :controller => '/whatever' instead of :controller =>
'whatever' in your link_to to force things into the root namespace.

Best,

I find it weird that it's doing that. If you use the correct restful
path, it should hit the right url

But you can try what Marnen suggested, seem hacky though..

Luis Saffie wrote in post #956383:

I find it weird that it's doing that. If you use the correct restful
path, it should hit the right url

Oh, yeah, named routes shouldn't be affected.

But you can try what Marnen suggested, seem hacky though..

I wouldn't call it hacky. Rails link_to, presumably by design, assumes
the current namespace unless otherwise specified.

Best,

Luis Saffie wrote in post #956383:

I find it weird that it’s doing that. If you use the correct restful

path, it should hit the right url

Oh, yeah, named routes shouldn’t be affected.

But you can try what Marnen suggested, seem hacky though…

I wouldn’t call it hacky. Rails link_to, presumably by design, assumes

the current namespace unless otherwise specified.

i ddint know that. good to know. is there a way of setting this dynamically?
thx
tom