Problem with nested resources with Kaminari pagination gem

谁说胖子不能爱 提交于 2019-12-08 08:39:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!