jquery rails ajax

so I am using jquery and updating a dom element with

$('#thelist').replaceWith("<%= escape_javascript(render(:partial => @deals)) %>");

this works fine except it is not hitting the server so if @deals is updated, it is not refreshing and showing the latest version. My question is how to ajax this thing so that it will update to the latest version of @deals. The full code is: onPullDown: function () {             setTimeout(function () {

                $('#thelist').replaceWith("<%= escape_javascript(render(:partial => @deals)) %>");                 myScroll.refresh();             });         },

thanks in advance!

That makes sense. When your page loads, the value of @deals is inserted in the JavaScript that is sent to the client. As you noticed, since your JavaScript code never makes a request back to the server, it just keeps calling replaceWith on the value of the original @deals.

The easiest way is probably to have some type of update action that responds to JS. Then in your view, you can render the newly refreshed @deals. You’ll also need to update your JavaScript to hit this action on the server and update your DOM element with the result. Here are some rough code examples.

In your controller:

def some_update @deals = Deal.all end

In some_update.js.erb:

<%= escape_javascript(render(:partial => @deals)) %>

Then change your JavaScript to hit some_update and use the result of some_update:

onPullDown: function () { setTimeout(function () {
.ajax({ url: ‘controller/some_update.js’, success: function(data) { $(‘#thelist’).replaceWith(data); myScroll.refresh(); } }); }); },