【问题标题】:Where do I put the ".paginate" call on this filtered object?我在哪里对这个过滤的对象进行“.paginate”调用?
【发布时间】:2013-10-31 11:58:27
【问题描述】:

我想对索引页面上列出的约会进行分页,但我不确定将分页消息放在哪里。以下是我在控制器中实现索引方法的方式:

def index
    if !current_user.nil?
      filter = []
      @my_apps = Appointment.joins(:client).where("user_id = ?", current_user.id)

      if !params[:paid].blank?
        paid = params[:paid]
        filter << ["copay_received = '#{paid.to_s}'"]
      end

      if !params[:effective_on].blank?
        junk = params[:effective_on]
        filter << ["clients.effective_on >= '#{junk.to_s}'"]
      end 

      @unpaids = @my_apps.where(filter.join(" AND "))  
    else
      redirect_to '/signin'
    end
  end
end

我尝试在 @my_apps 的 where 子句和 where 子句之后将 .paginate(page: params[:page]) 附加到 Appointment 对象,但没有成功。

请让我知道我做错了什么。

【问题讨论】:

    标签: ruby-on-rails pagination ruby-on-rails-4 will-paginate


    【解决方案1】:

    设置@my_apps后尝试这样做。

    比如……

    @my_apps = Appointment.joins(:client).where("user_id = ?", current_user.id)
    @my_apps = @my_apps.paginate(page: params[:page])
    

    我遇到了和你一样的问题,但这解决了我的分页问题。

    【讨论】:

      猜你喜欢
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 2011-01-27
      • 1970-01-01
      • 2011-07-16
      • 2020-04-27
      • 2015-08-16
      相关资源
      最近更新 更多