Question

I'm trying to use will_paginate but it didn't work for me maybe I'm doing things wrong this is my users controller

  def index
    @users = (current_user.blank? ? User.all : User.find(:all, :conditions => ["id != ?", current_user.id])).paginate(page: params[:page], per_page: 10)
  end

but I get this error undefined methodpaginate'`

Was it helpful?

Solution

Are you certain that you've included "will_paginate" in your Gemfile, run bundle install and restarted your server? If not, can you include the whole stacktrace?

Also, if you want to, you can restructure to Rails 4 style scoping like this:

def index
  @users = user_scope.paginate(page: params[:page], per_page: 10)
end 

private

def user_scope
  current_user ? User.where.not(id: current_user.id) : User.all
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top