简体   繁体   English

Rails:will_paginate未定义方法`paginate'

[英]Rails: will_paginate Undefined method `paginate'

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 我正在尝试使用will_paginate,但是它对我没有用,也许我做错了这是我的用户控制器

  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 method paginate'` 但是我得到这个错误undefined method paginate'`

Are you certain that you've included "will_paginate" in your Gemfile, run bundle install and restarted your server? 您确定您已在Gemfile中包含“ will_paginate”,运行bundle install并重新启动服务器了吗? If not, can you include the whole stacktrace? 如果没有,您可以包括整个堆栈跟踪信息吗?

Also, if you want to, you can restructure to Rails 4 style scoping like this: 此外,如果需要,您可以像这样重新构建Rails 4样式范围:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM