will_paginate 与资源路由集合

发布于 2024-12-26 10:48:28 字数 658 浏览 0 评论 0原文

不太明白这里发生了什么。因此,在我的路线中,我

sso.namespace(:admin) do |admin|
  admin.resources :locations, :collection => {:search => :post}

在视图上生成分页效果很好。这是我的视图代码:

<%= will_paginate @search_locations, :class => "loc_pagination", :params => {:controller => 'sso/admin/locations', :action => 'search'}, :style => "text-align: center;" if @search_locations %>

问题是,当我单击链接时,它会触发 GET 请求并将搜索保留在参数中。这是服务器日志中的参数。

Parameters: {"action"=>"show", "id"=>"search", "page"=>"2", "controller"=>"sso/admin/locations"}

生成的 html 代码看起来不错,但我不知道它做错了什么。

Can't quite figure out what's going on here. So in my routes I have

sso.namespace(:admin) do |admin|
  admin.resources :locations, :collection => {:search => :post}

Generating the pagination just fine on the view. Here's my view code:

<%= will_paginate @search_locations, :class => "loc_pagination", :params => {:controller => 'sso/admin/locations', :action => 'search'}, :style => "text-align: center;" if @search_locations %>

Problem is that when I click on the links, it fires a GET request and sticks search in the params. Here is the parameters in the server log.

Parameters: {"action"=>"show", "id"=>"search", "page"=>"2", "controller"=>"sso/admin/locations"}

The generated html code looks sound, but I can't figure out what it's doing wrong.

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

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

发布评论

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

评论(1

此生挚爱伱 2025-01-02 10:48:28

您已将搜索操作配置为仅响应 post 请求。当您尝试访问搜索结果的第二页(通过 get 请求)时,显示路由会获取响应。尝试更改 :collection => {:搜索=> :any } 并将搜索词附加到传递给 will_paginate 的参数中。

You've configured the search action to only respond to post requests. When you attempt to visit the second page of the search results (via a get request) the show route picks up the response. Try changing the :collection => { :search => :any } and append the search term to the params passed to will_paginate.

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