Hi guys,
I've done a tiny bit of ajax before, but now I'm trying out rjs templates and functions.
I'm trying to re-create something like http://live.lmgtfy.com with periodically_call_remote. The problem is when I try to use an rjs template, or rjs in the controller.
I've got a controller action that pulls a record from the database, sets the 'seen' flag and then attempts to append the body of the record to a list.
The rjs template looks like this:
update_page do |page| page.insert_html :bottom, 'content', "<li class='quote'>#{@quote}</li>" end
And if I try it from the controller it looks like this:
render :update do |page| page.insert_html :bottom, 'content', "<li class='quote'>#{@quote}</li>" end
Either way it seems to fail to output the appropriate JS and instead outputs:
try { } catch (e) { alert('RJS error:\n\n' + e.toString()); alert(''); throw e }
This happens no matter what I try to get the JS to do. If I just write the record to the view (ie have it completely replace the list rather than append to it) it works perfectly.
The idea is that when the remote call happens it should append the quote to the list, or, if there is no unread quote waiting, it should just do nothing. Right now I'd just like it to append and I'll work on the conditional later.
Am I missing something with RJS? I'm not sure if I've explained myself very well, so please ask for clarification if necessary.
Many thanks
Matt