views:

34

answers:

3

Hi,

I am trying to get paginating to work with jQeury. I am using the will_paginate gem. It works normally (with no javascript). I tried following a railscast (http://railscasts.com/episodes/174-pagination-with-ajax) but I am still having a problem.

show.js.erb

$('#comments').html("<%= escape_javascript(render "comments/comment.html.erb") %>");

This works when the partial file is just html. IE no <% code like this %>. Why? Is .html the wrong jQuery function to call? What should I use?

From trying lets of things, this code might be the problem:

$(".pagination a").click(function() {
    //$(".pagination").html("Page is loading...");
    $.get(this.href, null, null, "script");
    return false;
  });

what is "script"?

A: 

Although I don't know ruby, according to the page you linked, are missing a pair of parenthesis:

$('#comments').html("<%= escape_javascript(render("comments/comment.html.erb")) %>");

path411
Thanks, but that makes no difference :)
GreenRails
Sorry, I tried =/
path411
A: 

I don't use ruby and I'm fairly uninitiated to jQuery, but if I'm interpreting this correctly, you're trying to add HTML to an element entirely on the client side, then expecting server-side markup to be parsed within it.

This code never executes on the server. In order to get server-side markup parsed, you'd need to actually perform another server request (e.g. with XMLHttpRequest), which would perhaps process a file with this exact markup with it on the server, which would then process your server-side directives.

You'll probably be interested in jQuery's load function for this.

Ken
A: 

After much tinkering I found my problem:

I added this to my partial:

<%= will_paginate @comments %>
<% @comments.each do |comment| %>
//partial stuff
<% end %>

The screencast didn't show where he put the will_paginate line, so I assumed it stayed in the post file. It also didn't show the loop in the partial file. I didn't realise you had to do this since rails does it anyway when you call a partial file.

GreenRails
also render @comments makes duplicates whereas render comments/comment doesn't.
GreenRails