質問

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.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top