>> User.all.class
=> Array
>> User.paginate(:page => 1).class
TypeError: can't convert nil into Array
不起作用,但是
>> User.all.class
=> Array
>> User.all.paginate(:page => 1).class
=> WillPaginate::Collection
似乎没问题
def index
@title = "All users"
@users = User.all.paginate(:page => params[:page])
end
这对吗?
答案 0 :(得分:0)
如果您使用的是“will paginate”gem,则以下代码应该适合您。
def index
@title = "All users"
@users = User.paginate page => params[:page], :per_page => 10
end