Adt Adt - 6 months ago 88
Javascript Question

Rails Kaminari example infinite scroll not working

I am trying to implement kaminari rails infinite scroll using this example.
It is working fine in my other apps but not working in this app.
Kaminari example

My company controller

def index
@companies = Company.all.page(params[:page]).per(4)
end


My index.html.erb

<div class="posts">
<div class="page">
<%= render @companies %>
</div>
</div>
<%= paginate @companies %>


My _company.html.erb

<div class="post">
<% company_decorator = CompanyDecorator.new(company)%>
<h4><%= company.name %> ||
No. of operations: <%= company_decorator.number_of_operations %> ||
Average Amount : <%= company_decorator.average_of_amount %> ||
Highest of Month: <%= company_decorator.highest_of_month%> ||
Accepted Operations: <%= company_decorator.accepted_operations%>
</h4>
<ul>
<% company.operations.each do |operation| %>
<li><%= operation.id%></li>

<%end%>
</ul>
</div>


My assets/javascripts/companies.js.coffee

$(document).ready ->
$(".posts .page").infinitescroll
navSelector: "nav.pagination"
nextSelector: "nav.pagination a[rel=next]"
itemSelector: ".posts .post"


My index.js.erb

$(".posts").append("<div class='page'><%= escape_javascript(render(@companies)) %></div>");


I am unable to find problem please help me. This same code is working in my other app.

Answer

Try def index @companies = Company.all.page(params[:page]).per(25) end playing with the pagination length.. I've heard that sometimes works

Comments