Raman M Raman M - 1 year ago 105
jQuery Question

Ajax pagination with kaminari

I have a rails application and I am trying to add pagination with kaminari.

I have a controller action like this.

def index
@hotels = Kaminari.paginate_array(@hotels).page(params[:page]).per(5)

My index.html.haml
= render :partial => 'hotel_rightside', :locals => {:hotels => @hotels}

My hotel_rightside partial
- if hotels.present?
= render :partial => 'hotel_details', :locals => {:hotels => @hotels}
= paginate @hotels, :remote => true

My index.js.erb
$('#hotels_listing').html('<%= escape_javascript(render :partial => "hotel_details", :locals => {:hotels => @hotels }) %>');
$('#hotels_pagination').html("<%= escape_javascript(paginate(@hotels, :remote => true)) %>");

Right now it makes an HTML request even though I have added remote true.

How can I make it into an ajax request ?

Answer Source

I guess you are using custom kaminari views in your project so look into your views and find out if this :remote => remote present or not if not then add it in link_to_unless helper options.


= link_to_unless page.current?, page, url, {:rel => page.next? ? 'next' : page.prev? ? 'prev' : nil , :class => "page-link", :remote => remote}