Mapping a resource to a subdirectory controller

View: New views
3 Messages — Rating Filter:   Alert me  

Mapping a resource to a subdirectory controller

by Jake Boxer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


My app (like so many others) has an admin section, which uses
controllers inside an admin directory. To keep it simple, I'm only
administering the User resource for now. I have a controller that
looks like this:

<code>
class Admin::UsersController < ApplicationController
  # normal scaffold methods in here
end
</code>

I've also added the following lines to my routes.rb file:

<code>
map.namespace :admin do |admin|
  admin.resources :users
end
</code>

In my admin/users/index view, I'd like to be able to use link_to to
create a delete link for each user. If I wasn't using subdirectories,
it would be like this:

<code>
<%= link_to "Delete", user, :confirm => "Are you sure?", :method
=> :delete %>
</code>

When I put this code in admin/users/index, it links to the regular
users section (not the admin one), which has no destroy method. How
can I make this link to the admin version? Do I need to hardcode the
URL into the link_to method, or is there a cleaner way that I don't
know about?

Thanks
-Jake
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Mapping a resource to a subdirectory controller

by Jake Boxer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


P.S. Sorry about the <code> tags. I was hoping they'd work, but I
guess not. Hopefully their intent is clear.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Mapping a resource to a subdirectory controller

by Jake Boxer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Figured it out. The correct code for each resource action is:

<%= link_to "Index", admin_users_path %>
<%= link_to "Show", admin_user_path(user) %>
<%= link_to "Edit", edit_admin_user_path(user) %>
<%= link_to "Delete", admin_user_path(user), :confirm => "Are you
sure?", :method => :delete %>

The users/user thing was throwing me off.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---