views:

164

answers:

2

In my application I have a namespaced admin section. Here's a snippet from my routes.rb:

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

map.resources :contents

Within my admin namespace, right now I am using the following:

link_to content, admin_content_path(content)

But I want to do:

link_to content, content

Which is currently equivalent to:

link_to content, content_path(content)

Is there a way to have all links within views belonging to a controller be prefixed with a namespace?

+1  A: 

if i am reading you correctly, you can do

link_to content, [:admin, content]

this should get you to admin_content_path(content). assuming of course the content is a valid variable (looks like you took this code from a block in an index scaffold view).

There is no prefix to apply to all restful links in a view, however. May i suggest just using the restful notation of admin_content_path(content) henceforth.

pjammer
A: 

It looks like you are mapping contents twice, which is weird. You don't need to use nested resources here, that is for the situation where admin is an object that has_many contents, which is unlikey in your case. I recommend dropping the nested resource and trying the following.

:path_prefix - Set a prefix to the routes with required route variables.

map.resources :contents, :path_prefix => '/admin'
MattMcKnight
I'm not using a nested resource - I'm using a namespace.I have two references to contents because I want to have two different sets of views on it - admin and normal user.
Paul McMahon