Neeraj Yadav
Neeraj Yadav

Reputation: 145

undefined method `page' for nil:NilClass, paginate_with_kaminari

I am using paginate_with_kaminari gem for implementing pagination in my rails application. Sometimes I get this error "undefined method `page' for nil:NilClass".

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

In the above code, params[:page] will be present which contains page number which has to be fetched.

Upvotes: 1

Views: 1115

Answers (1)

Siddhartha Narang
Siddhartha Narang

Reputation: 136

If no results are fetched then it will return nil . In that case @notifications will be empty . But in "current_user.push_records.where(:n_status.in => [PushRecord::N_STATUS[:NEW_REGISTERED],PushRecord::N_STATUS[:UNINSTALLED]])" if you use some other method of array like sort or some other functions then in that case sort can't be done for nil class and will throw error .

Upvotes: 1

Related Questions