开发者

1railstutorial.org 10.3.3 Pagination error?

开发者 https://www.devze.com 2023-01-27 09:34 出处:网络
>> User.all.class => Array >> User.开发者_如何学JAVApaginate(:page => 1).class TypeError: can\'t convert nil into Array
>> User.all.class
=> Array
>> User.开发者_如何学JAVApaginate(:page => 1).class
TypeError: can't convert nil into Array

not work, but

>> User.all.class
=> Array
>> User.all.paginate(:page => 1).class
=> WillPaginate::Collection

seems OK and

  def index
    @title = "All users"
    @users = User.all.paginate(:page => params[:page])
  end

this right?


If you are using the "will paginate" gem, this following code should work for you.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号