Im trying to make a system that informs the user of any new private messages, the index method of the messages controller creates to instance variables of @messages and @newmessages, both are used in index.html.erb and i want to make it so that index.js.erb makes the flash message box on my site appear.
Ive got jquery to run a function every few seconds, the function that gets run is
function checkagain(){
//Start a Timer, dont want it bombarding the server with constant requests
$.timer(10000,function(){
$.getScript("/messages.js");
//RECURSE, see you again in 10 seconds
checkagain();
});
}
$.getScript doesnt seem to make it run the code on index.js.erb which is simply:
alert("RESPONDING");
I cant seem to get it to trigger the code on that page.
I have found that /messages.js that doesn't return any javascript, just the same as index.html.erb
the index action of the controller is:
def index
@messages = Message.find(:all, :conditions => "receiver_id = '#{current_user.id}' AND `read` = '1'")
@newmessages = Message.find(:all, :conditions => "receiver_id = '#{current_user.id}' AND `read` = '0'")
end