Note that there are some explanatory texts on larger screens.

plurals
  1. POrails infinite scroll ajax actions on page > 1 items
    primarykey
    data
    text
    <p>Let me first state that this is an instance of using a lot of other peoples' code and not completely understanding what's going on and how to fix my issue.</p> <p>I followed the Railscast for infinite scroll using will_paginate, and have that working fine.</p> <p>I load 12 items per page, each in it's own partial. Each item is an object that a user can 'like' by clicking a 'thumbs up' button.</p> <p>I ajax-ified this button, and reload the partial for the item that is 'liked'.</p> <p>This works fine on items 1-12 (the first page).</p> <p>When a user clicks the thumbs up button on an item that is loaded via infinite scroll, the ajax call executes, but doesn't find the object again, and the partial simply goes blank.</p> <p>Here's my code-</p> <pre><code>#@messages partial &lt;div class="span3 well" style="height:360px;" id="message-&lt;%=message.id%&gt;"&gt; &lt;div class="thumbnail"&gt; &lt;%= image_tag message.gif.url %&gt; &lt;div class="caption"&gt; &lt;h5&gt;&lt;%=link_to message.sender, "/profile/#{User.find_by_username(message.sender).id}"%&gt;&lt;/h5&gt; &lt;h5&gt;&lt;%=message.chain.subject %&gt;&lt;/h5&gt; &lt;p&gt;&lt;em&gt;"&lt;%= message.content %&gt;"&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="/upvote/&lt;%=message.id%&gt;" data-remote="true" class="btn btn-success"&gt;&lt;%=message.up_votes%&gt; &lt;i class="icon-thumbs-up"&gt;&lt;/i&gt; Nice Work&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; # js.coffee (from railscast) jQuery -&gt; $(window).scroll -&gt; url = $('.pagination .next_page').attr('href') if url &amp;&amp; $(window).scrollTop() &gt; $(document).height() - $(window).height() - 50 $('.pagination').text('Loading more gifs...') $.getScript(url) # vote.js -- js executed by ajax call $("#message-&lt;%=params[:id]%&gt;").load(location.href+" #message-&lt;%=params[:id]%&gt;&gt;*", ""); </code></pre> <p>I'm pretty certain the problem is in the vote.js. the <code>.load(location.href+" #message-&lt;%=params[:id]%&gt;&gt;*", "");</code> seems to not be able to find the objects on the 2nd, 3rd, 4th, etc. pages because it uses <code>location.href</code> which, as the current url, only supplies the first 12 objects. I think I need to somehow put the page in that url, but I'm not sure how to accomplish that.</p> <p>EDIT- Alternatively, maybe I should have an endpoint for all messages that isn't paginated, and call that url instead of <code>location.href +</code> ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload