link_to中的奇怪路由问题;一定要简单

时间:2009-12-31 20:52:50

标签: ruby-on-rails routing link-to-remote

在假期前,我的大脑正在努力挤压一些工作。

我正在尝试修复一个简单的错误。以下link_to_remote创建的URL错误:

options = {
    :url => { :controller => 'favorites', :action => 'resort', :params => params.merge({:sort => key, :method => method})},
    :update => 'favorites'
}
html_options = {
  :title => "Sort by this field",
  :href => url_for(:controller => 'favorites', :action => 'resort', :params => params.merge({:sort => key, :method => method}))
}
link_to_remote("hithere", options, html_options)

它正在创造:

http://localhost:3000/favorites?method=ASC&sort=title

而不是:

http://localhost:3000/favorites/resort?method=ASC&sort=title

指定的路线是:

  map.favorites_resort           "/favorites/resort",                                    :controller => "favorites", :action => "resort"
  map.favorites_search           "/favorites/search",                                    :controller => "favorites", :action => "search"
  map.toggle_message_favorite    "/favorites/toggle_message_favorite/:message_id",       :controller => "favorites", :action => "toggle_message_favorite"
  map.toggle_attachment_favorite "/favorites/toggle_attachment_favorite/:attachment_id", :controller => "favorites", :action => "toggle_attachment_favorite"
  map.resources :favorites

我的猜测是它与某些路由优先级有关,但我无法弄清楚哪个...谢谢!

根据jasnow的建议,将路线改为: map.favorites_resort“/ favorites / resort / sort /:sort / method /:method”

1 个答案:

答案 0 :(得分:1)

在路线文件中查找“/:”。