1railstutorial.org 10.3.3分页错误?

时间:2010-11-27 17:21:38

标签: ruby-on-rails

>> 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

这对吗?

1 个答案:

答案 0 :(得分:0)

如果您使用的是“will paginate”gem,则以下代码应该适合您。


 def index
  @title = "All users"
  @users = User.paginate page => params[:page], :per_page => 10
 end