link_to中奇怪的路由问题;一定是简单的事情
我的大脑很煎熬,试图在假期前挤出一些工作。
我正在尝试修复一个简单的错误。以下 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"
My brain is fried trying to squeeze some work in before the holiday.
I'm trying to fix a simple bug. The URLs that the following link_to_remote is creating are wrong:
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)
It is creating:
http://localhost:3000/favorites?method=ASC&sort=title
instead of:
http://localhost:3000/favorites/resort?method=ASC&sort=title
The routes specified are:
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
My guess is it has to do with some routing priorities but I can't figure out which... Thanks!
On jasnow's suggestion, changed routes to:
map.favorites_resort "/favorites/resort/sort/:sort/method/:method"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在路由文件中查找“/:”。
Look for the "/:" in your routes file.