简体   繁体   中英

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 ? for dynamic url segments, the client on my project doesn't want them.

So does anyone know how, using Kaminari for paging, I can change the routing to replace:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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