Quick qeustion about periodically_call_remote
|
|
Hi all, Im building a blog engine, and Im trying to get the posts to autosave every 2 minutes or so as the author is writing them. I googled the subject, and found a nice little tutorial that suggested using periodically_call_remote to update the draft as it is being written. The only problem is, I can only partially get it to work. I have this code for my periodically_call_remote (in my _form partial): <%= periodically_call_remote( :update => ‘results’, :url => { :action => ‘save_draft’, :id => @draft.id }, :complete => visual_effect(:highlight, ‘results’), :frequency => 120, :with => ”’title=’ + escape($F(‘post_title’)) + ‘&body=’ + escape($F(‘post_body’))”) %> and the method it calls looks like this (in the blog controller): def save_draft @title = params[:title] @body = params[:body] @draft = Draft.find(params[:id]) if @draft.update_attributes(:title => @title, :body => @body) render :text => ‘Draft saved’ else render :text => ‘Draft was not saved; there was a problem’ end end Now, the issue I run into is that the draft never actually gets saved with this setup. The div that is supposed to be updated by periodically_call_remote also never gets updated. This leads me to believe that no data is being sent at all, or the function is just breaking and not throwing an exception. I found that if I remove the last part of the function, being the :with part, it works, granted it just flashes the message on the blog page, but it works. So, I guess my question is, what am I doing wrong? Obviously its something in the :with clause, but I dont know enough about Rails yet to figure out. Any and all help will be greatly appreciated. |