Question

I'd like to paginate the appointments listed on my index page, but i'm not sure where to put the paginate message. Here's how I've implemented my index method in the controller:

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

I've tried appending .paginate(page: params[:page]) to the Appointment object, after the where clause and after the where clause of @my_apps but no luck.

Please let me know what I'm doing wrong.

Was it helpful?

Solution

Try doing it after you set @my_apps.

For instance...

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

I ran into the same problem as you, but this fixed my issue with pagination.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top