will_paginate 路由仅适用于页面 > 1

发布于 2024-08-29 07:04:32 字数 505 浏览 6 评论 0原文

我定义了以下路由:

map.resources :categories, :has_many => :downloads
map.resources :downloads, :member => {:go => :get}, :collection => {:tag => :get}
map.connect '/downlods/page/:page', :controller => 'downloads', :action => 'index'
map.connect '/categories/:category_id/downloads/page/:page', :controller => 'downloads', :action => 'index'

出于某种原因,调用 will_paginate 帮助程序的第一个页面会导致呈现带有 ?page=2 的链接,而后续页面则具有带有 /downloads/page/2 的链接。你知道这可能是什么原因造成的吗?

I have the following routes defined:

map.resources :categories, :has_many => :downloads
map.resources :downloads, :member => {:go => :get}, :collection => {:tag => :get}
map.connect '/downlods/page/:page', :controller => 'downloads', :action => 'index'
map.connect '/categories/:category_id/downloads/page/:page', :controller => 'downloads', :action => 'index'

For some reason, the first page that the will_paginate helper is called on causes links with ?page=2 to be rendered, while subsequent pages have links with /downloads/page/2. Do you know what might be causing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

挽梦忆笙歌 2024-09-05 07:04:32

如果您只是使用 map.connect 声明一条路线,那么如果您执行以下操作,则它的路由方式可能会出现问题:

link_to("Next", :page => 2)

您可能想要做的是命名该路线,然后以这种方式使用它:

map.downloads_paginated '/downloads/page/:page', :controller => 'downloads', :action => 'index'

然后您使用该路线按名称:

link_to("Next", downloads_paginated_path(2))

这些更可靠。

请注意,您的路径中有“/downloads”而不是“/downloads”,但我不确定这会导致所描述的问题。

If you simply declare a route with map.connect, it can be hit and miss as to how it's routed if you do something like:

link_to("Next", :page => 2)

What you might want to do is name the route and then use it that way:

map.downloads_paginated '/downloads/page/:page', :controller => 'downloads', :action => 'index'

Then you use the route by name:

link_to("Next", downloads_paginated_path(2))

These are much more reliable.

As a note, you have '/downlods' in your path instead of '/downloads' but I'm not sure that'd be causing the trouble described.

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