开发者

Problem with nested resources with Kaminari pagination gem

开发者 https://www.devze.com 2023-02-20 01:06 出处:网络
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.

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


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.


Ooops. Just realised, apparently a route was being prioritized....

Seems to work now...

0

精彩评论

暂无评论...
验证码 换一张
取 消