jquery - Rails 3.2: Why does will_paginate page link disapear after first click -
i'm trying implement jquery ajax rails app , far it's working, there bug unable wrap head around. basically, have books page lists books using will_paginate group them in pages of 5 each.
my index.html.erb file books view has snippet of code:
<div id="page_paginate"> <%= will_paginate @books %><br /> <%= render @books %> </div>
the @books partial saved _book.html.erb , looks this:
<div class="books_box"> <h1><%= book.title%><span>(<%=link_to book.author.name, book.author%>)</span></h1> <img alt="image" src="<%= book.image_url %>"> <div class="book_info"> <div class="detail_button"><%= link_to "details", '#' %></div> <div class="like_button"><%= link_to "like", '#' %></div> </div
in application.js file, have following code:
$(function() { $("#page_paginate .pagination a").live("click", function() { $.getscript(this.href); return false; }); });
and have index.js.erb file in views/books directory:
$("#page_paginate").html("<%= escape_javascript(render(@books))%>")
the issue is:
while pagination works ajax; pages turn without page reloading , all, pagination links disappear after first click nd have go books_url show again. have tried putting <%= will_paginate %> in books partial way:
<%= will_paginate @books %><br /> <div class="books_box"> <h1><%= book.title%><span>(<%=link_to book.author.name, book.author%>)</span></h1> <img alt="image" src="<%= book.image_url %>"> <div class="book_info"> <div class="detail_button"><%= link_to "details", '#' %></div> <div class="like_button"><%= link_to "like", '#' %></div> </div </div>
but way, page links show on top of every listing. aim have pagination links show above , below the end of every page. figure it's problem loops or place links have tried novice mind possibly conceive. appreciate little help. thanks
when following code runs
$("#page_paginate").html("<%= escape_javascript(render(@books))%>")
it removes within <div id="page_paginate">
:
<div id="page_paginate"> <%= will_paginate @books %><br /> <!-- removed. --> <%= render @books %> <!-- removed. --> </div>
before applies .html("<%= escape_javascript(render(@books))%>")
.
to prevent <%= will_paginate @books %><br />
being removed, wrap <%= render @books %>
in <div>
follows:
<div id="page_paginate"> <%= will_paginate @books %><br /> <div id="books_render"> <%= render @books %> </div> </div>
and select #books_render
instead of #page_paginate
in index.js.erb
:
$("#books_render").html("<%= escape_javascript(render(@books))%>")
Comments
Post a Comment