views:

20

answers:

1

I have a Store model. And two controllers:

  • stores_controller
  • admin/stores_controller

now in the list view of the admin/stores_controller I am trying to generate a link to the destroy action in the admin/stores_controller but every variation I have tried either goes to the stores_controller (so not the admin one) or to some other incorrect url.

I am currenty using

<%= link_to "Delete", :controller => "admin/stores", 
            :action => "destroy", :id => store, :method => :delete %>

but this generates a url like http://localhost:3000/admin/stores/5?method=delete which invokes the show action instead of the destroy one.

in routes.rb I have

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

map.resources :stores

How do I fix this?

+1  A: 

When you have a namespace, use link_to like so:

link_to 'Show', [:admin, @var]

Similarly, if you want to reference a form:

form_for([:admin, @var])

etc.

JRL