简体   繁体   中英

Load More button “per_page” giving error

Im trying to make a load more button that will load 4 items at a time. Im using will_paginate and kaminari . Im getting an error with this current code:

1) I get this error when loading the page and having the per_page part in the controller object.: undefined method 'to_model' for 2:Fixnum

  • I just need to figure out how to add the number of items per page then i can continue with the js.

 <%= link_to 'show_more', @reservations_completed.next_page, :remote => true, :id => 'show_more_link' %> 

@reservations_completed = current_user.reservations.where("turned_in = ?", true).where("completed_doc_updated_at <= due_date", true).order(created_at: :desc).paginate(:page => params[:page], :per_page => 4)

2) I'v also tried the code below and got this error: undefined method 'last_page?' for undefined method 'last_page?' for

@reservations_completed = user.reservations.where("turned_in = ?", true).where("completed_doc_updated_at <= due_date", true).order(created_at: :desc).page(params[:page]).per_page(3)

 <%= link_to_next_page @reservations_completed, 'show_more', :remote => true, :id => 'show_more_link' %> 

In the first case you need to pass a path (the simplest way) as a second parameter to link_to , see docs . So for the first case it should be something like this:

<%= link_to 'show_more', route_path(page: params[:page].to_i + 1), id: 'show_more_link', remote: true %>

where route_path is the url_helper for your route.

The second case: try to replace .per_page(3) to .page(3) as states in the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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