问题
Can't seem to get Kaminari to work properly with nested resources. Here is a description of my problem. Wondering if anybody was able to tackle this issue.
My routes look like:
resources :artists do
resources :paintings
end
In my view, I have:
<%= paginate @paintings, :params => { :controller => 'paintings', :action => 'index' } %>
The initial / base url looks like this:
http://localhost/artists/foobar/paintings
But clicking on a kaminari paginate link, renders the url like this:
http://localhost/paintings?artist_id=foobar&page=2
It's supposed to be:
http://localhost/artists/foobar/paintings?page=2
回答1:
I've just had this same problem myself - in case anyone else ends up on this page this is how I solved it:
In routes.rb you need to move your "outer" route to below your nested. So if you had:
resources :questions
resources :subject_areas do
resources :questions
end
you need to change it to:
resources :subject_areas do
resources :questions
end
resources :questions
This made the pagination links start working as expected above.
回答2:
Ooops. Just realised, apparently a route was being prioritized....
Seems to work now...
来源:https://stackoverflow.com/questions/5457580/problem-with-nested-resources-with-kaminari-pagination-gem