RamanSM
RamanSM

Reputation: 283

Rails: AJAX pagination with Kaminari gem

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 ?

Upvotes: 1

Views: 2140

Answers (1)

Amit Sharma
Amit Sharma

Reputation: 3477

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}

Upvotes: 1

Related Questions