will_paginate 与资源路由集合
不太明白这里发生了什么。因此,在我的路线中,我
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将搜索操作配置为仅响应
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.