Using custom paths with will_paginate gem

174 views Asked by At

I've got the following in routes.rb:

# Legacy Search URL
get "/used-guitars/search", to: 'guitars#index', as: 'legacy_search'

And I'm trying to get the will_paginate gem to use my legacy_search urls when paginating the index action for the guitars controller:

= will_paginate @guitars

Results in pagination links with href's like so:

/guitars?page=2

When what I want is:

/used-guitars/search?page=2

I've had a read through the code and there is no option to provide a path parameter.

What to do? I will abandon will_paginate if I can't get this working, I'll just write my own code if I have to because this is a showstopper.

1

There are 1 answers

0
stephenmurdoch On BEST ANSWER

I fixed this by moving my legacy route above the other one like so:

get "/used-guitars/search", to: 'guitars#index', as: 'legacy_search'
resources :guitars

Easy when you know how.