简体   繁体   English

带有Kaminari 0.17.0的Rails 4.2-如何将“?page = x”更改为“ / x”(即无查询字符串)

[英]Rails 4.2 with Kaminari 0.17.0 - how to change “?page=x” to “/x” (ie no query string)

Whilst I understand that Tim Berners Lee specified the use of ? 虽然我知道Tim Berners Lee 指定使用? for dynamic url segments, the client on my project doesn't want them. 对于动态url段,我项目上的客户端不需要它们。

So does anyone know how, using Kaminari for paging, I can change the routing to replace: 所以没有人知道如何使用Kaminari进行分页,我可以更改路由以替换:

domain.com/searchresults?page=x

with

domain.com/searchresults/x

Obviously, this has to work when you click next page, prev page etc so that the url always changes x to the correct page number. 显然,当您单击下一页,上一页等时,此方法必须起作用,以便url始终将x更改为正确的页码。

From the docs I missed that you can add a concern in the routes, like this: 从文档中我错过了您可以在路线中添加关注点,例如:

concern :paginatable do
  get '(page/:page)', :action => :index, :on => :collection, :as => ''
end

Then apply the concern: 然后应用关注点:

resources :my_resources, :concerns => :paginatable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM