Rails 5 using will_paginate to create a load more button

前端 未结 2 702
野趣味
野趣味 2021-02-04 20:26

So I\'m trying to create a load more button (not infinite scroll although some simple js tweaks could make it so). I\'m using the will_paginate gem in Rails 5.

Its curre

相关标签:
2条回答
  • 2021-02-04 21:23

    If you check the server console, you can actually see two requests coming in, one triggered by your :remote => true enabled link and other from your custom ajax. Actually you don't need any js to make this work. Just remove that click function from your pagination.js.coffee or remove :remote => true from the link. After all both are doing the same thing. Hope this will help.

    0 讨论(0)
  • 2021-02-04 21:24

    So it was a stupid error of course.

    Remove the line on index.html.erb:

    :remote => true if @links.next_page
    

    So now it looks like this:

    <div class="link-wrap">
      <%= render @links %>
    </div>
    <% if @links.next_page %>
      <div class="link more">
      <%= link_to 'Load More', links_path(:page => @links.next_page), :class => 'next_page' %>
      </div>
    <% end %>
    

    All works fine now!

    0 讨论(0)
提交回复
热议问题