开发者

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

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 oth开发者_开发问答er 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜