How to Implement ajax pagination with will_paginate gem

前端 未结 6 940
遥遥无期
遥遥无期 2020-12-02 10:19

I am using will_paginate gem in my ROR project to show the records in pages.

I want the next page to be loaded without reloading the whole

6条回答
  •  温柔的废话
    2020-12-02 10:50

    To follow on from @Pierre's excellent answer re creating a helper, I've seen some follow up questions regarding updating the views (a problem I initially had). @Pierre follows up with that problem by stating that you need to create a js response. Here's what I did after creating the helper:

    in my show.html.erb

    <%= render @comments %>
    <%= js_will_paginate @comments %>

    I created another file called show.js.erb (so two formats for show)

    // to update comments    
    $("#see-comments").html("<%= j render @comments %>");
    // to update the pagination links
    $("#pagination-comments").html('<%= js_will_paginate @comments %>');
    

提交回复
热议问题