Answer the question
In order to leave comments, you need to log in
Load more with the will_paginate gem?
Hello!
I'm trying to load items when clicking on the "load more" button.
I put the will_paginate gem.
Made the following link:
<%= link_to 'Показать больше', list_path(:page => @items.next_page), :class => 'load-more-posts', :remote => true%>
respond_to do |format|
format.html
format.json
format.js
$("#items_<%= @list.id %>").append("<%= escape_javascript(render @items.order(rating: :desc)) %>");
Answer the question
In order to leave comments, you need to log in
Similar is here
# posts_controller.rb
class PostsController < ApplicationController
def index
@posts = Post.paginate(page: params[:page], per_page: 3)
respond_to do |format|
format.html
format.js
end
end
end
# index.html
<div class="page-header">
<h1>My posts</h1>
</div>
<div id="my-posts">
<%= render @posts %>
</div>
<div id="more_posts">
<%= link_to "More posts...", posts_index_url(page: @posts.next_page), remote: true %>
</div>
# index.js.erb
$("#my-posts").append('<%= escape_javascript render(@posts)%>');
$("#more_posts").html('<%= escape_javascript(link_to("More posts...", posts_index_url(page: @posts.next_page), remote: true)) if @posts.next_page %>');
# _post.html.erb
<div>
<h2><%= post.title %></h2>
<small><em><%= post.created_at %></em></small>
<p><%= truncate(strip_tags(post.body), length: 600) %></p>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question