Kaminari 分页 gem 的嵌套资源问题
似乎无法让 Kaminari 与嵌套资源正常工作。这是我的问题的描述。想知道是否有人能够解决这个问题。
我的路线看起来像:
resources :artists do
resources :paintings
end
在我看来,我有:
<%= paginate @paintings, :params => { :controller => 'paintings', :action => 'index' } %>
初始/基本 url 看起来像这样:
http://localhost/artists/foobar/paintings
但是单击 kaminari 分页链接,会呈现这样的 url:
http://localhost/paintings?artist_id=foobar&page=2
它应该是:
http://localhost/artists/foobar/paintings?page=2
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己也遇到了同样的问题 - 万一其他人最终出现在这个页面上,这就是我解决它的方法:
在routes.rb中,您需要将“外部”路线移动到嵌套的下方。因此,如果您有:
您需要将其更改为:
这使得分页链接开始按上面的预期工作。
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:
you need to change it to:
This made the pagination links start working as expected above.
哎呀。刚刚意识到,显然一条路线正在被优先考虑......
似乎现在可以工作......
Ooops. Just realised, apparently a route was being prioritized....
Seems to work now...