Skip to content

Instantly share code, notes, and snippets.

@pol
Created July 28, 2008 21:25
Show Gist options
  • Save pol/2956 to your computer and use it in GitHub Desktop.
Save pol/2956 to your computer and use it in GitHub Desktop.
<% form_for @survey do |f| %>
<%= observe_form "edit_survey_#{@survey.id}",
:url => survey_path(@survey),
:method => :put,
:frequency => 5,
:update => 'savedat_time'
%>
<%#= the form... %>
<% end %>
The Javascript:
//<![CDATA[
new Form.Observer('edit_survey_3', 5, function(element, value) {new Ajax.Updater('savedat_time', '/surveys/3', {asynchronous:true, evalScripts:true, method:'put', parameters:value + '&authenticity_token=' + encodeURIComponent('d9b4e818b91f9d47b23abc1c5d9fc88c79795cc5')})})
//]]>
Or with jQuery:
//<![CDATA[
$('#edit_survey_3').delayedObserver(5, function(element, value) {$.ajax({data:value + '&_method=put' + '&authenticity_token=' + encodeURIComponent('d9b4e818b91f9d47b23abc1c5d9fc88c79795cc5'), success:function(request){$('#savedat_time').html(request);}, type:'post', url:'/surveys/3'})})
//]]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment