olle
olle

Reputation: 4595

Restful routing with different controllers for the same resource resolving the "wrong" url

I have a Store model. And two controllers:

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?

Upvotes: 0

Views: 171

Answers (1)

JRL
JRL

Reputation: 78033

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.

Upvotes: 1

Related Questions