Ruby on rails 未定义的方法`page';对于nil:NilClass,使用_kaminari对_进行分页

Ruby on rails 未定义的方法`page';对于nil:NilClass,使用_kaminari对_进行分页,ruby-on-rails,ruby,ruby-on-rails-3,kaminari,Ruby On Rails,Ruby,Ruby On Rails 3,Kaminari,我使用paginate_和kaminari gem在rails应用程序中实现分页。有时我会遇到这样的错误:“nil:NilClass的未定义方法`page' 在上面的代码中,将出现参数[:page],其中包含必须获取的页码。如果没有获取结果,则返回nil。在这种情况下,@通知将为空。但在“current_user.push_records.where(:n_status.in=>[PushRecord::n_status[:NEW_REGISTERED],PushRecord::n_status

我使用paginate_和kaminari gem在rails应用程序中实现分页。有时我会遇到这样的错误:“nil:NilClass的未定义方法`page'


在上面的代码中,将出现参数[:page],其中包含必须获取的页码。

如果没有获取结果,则返回nil。在这种情况下,@通知将为空。但在“current_user.push_records.where(:n_status.in=>[PushRecord::n_status[:NEW_REGISTERED],PushRecord::n_status[:Unsolalled]])中,如果使用其他数组方法,如sort或其他函数,则在这种情况下,无法对nil类进行排序,并将抛出错误

@notifications = paginate current_user.push_records.where(:n_status.in => [PushRecord::N_STATUS[:NEW_REGISTERED],PushRecord::N_STATUS[:UNINSTALLED]]).to_a , per_page: 20