Raman M Raman M - 4 months ago 28
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)
..
end

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

My hotel_rightside partial
- if hotels.present?
#hotels_listing
= render :partial => 'hotel_details', :locals => {:hotels => @hotels}
#hotels_pagination
= 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

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.

e.g.

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