Reputation: 637
I have a helper method in my application controller that check to see when an object has been created. Basically if the total number of objects changes it alerts you on the page load with a flash message. This code works fine, but what I want to do is eliminate the need to reload.
How would this be done? I understand the solution would likely involve AJAX, but I'm a newbie to AJAX and rails so I'm not sure how to go about this. Thanks for the help!
Upvotes: 2
Views: 2540
Reputation: 529
<script type="text/javascript">
var i = setInterval( "checkObjectCount()", 10000 );
function checkObjectCount() {
count = <%= @object_count %>;
$.ajax({
url: 'ajax/request_object_count',
success: function(data) {
if (data > count) {
$('#alert_container').show();
clearInterval(i);
}
}
});
}
</script>
Upvotes: 2