雷成&Rails 分页 - 未定义的方法“current_page" [英] Kaminari & Rails pagination - undefined method `current_page'

查看:34
本文介绍了雷成&Rails 分页 - 未定义的方法“current_page"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了又搜索,但没有解决我的问题.这是我的控制器:

I searched and searched, but nothing solved my problem. Here's my controller:

def show
    @topic = Topic.find(params[:id])
    @topic.posts = @topic.posts.page(params[:page]).per(2) # 2 for debugging
end

这个功能很好,因为主题视图减少到两个帖子.但是,当我将其添加到 show.html.erb 时:

That functions just fine, because the topic view is reduced to two posts. However, when I add this to show.html.erb:

<%= paginate @topic.posts %>

我收到了这个错误:

undefined method `current_page' for #<ActiveRecord::Relation:0x69041c9b2d58>

推荐答案

尝试:

def show
  @topic = Topic.find(params[:id])
  @posts = @topic.posts.page(params[:page]).per(2)
end

然后:

<%= paginate @posts %>

这篇关于雷成&amp;Rails 分页 - 未定义的方法“current_page"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆