link_to中奇怪的路由问题;一定是简单的事情

发布于 2024-08-16 04:03:33 字数 1564 浏览 5 评论 0原文

我的大脑很煎熬,试图在假期前挤出一些工作。

我正在尝试修复一个简单的错误。以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坦然微笑 2024-08-23 04:03:33

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

Look for the "/:" in your routes file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文