Kaminari 分页 gem 的嵌套资源问题

发布于 2024-10-27 10:07:02 字数 602 浏览 4 评论 0原文

似乎无法让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一萌ing 2024-11-03 10:07:02

我自己也遇到了同样的问题 - 万一其他人最终出现在这个页面上,这就是我解决它的方法:

在routes.rb中,您需要将“外部”路线移动到嵌套的下方。因此,如果您有:

resources :questions
resources :subject_areas do
  resources :questions
end

您需要将其更改为:

resources :subject_areas do
  resources :questions
end
resources :questions

这使得分页链接开始按上面的预期工作。

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.

深海里的那抹蓝 2024-11-03 10:07:02

哎呀。刚刚意识到,显然一条路线正在被优先考虑......

似乎现在可以工作......

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

Seems to work now...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文