Skip to content

Instantly share code, notes, and snippets.

@joshk
Created November 11, 2008 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshk/23787 to your computer and use it in GitHub Desktop.
Save joshk/23787 to your computer and use it in GitHub Desktop.
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
// Thanks to http://henrik.nyh.se/2008/05/rails-authenticity-token-with-jquery for the ajaxSend advice
// Adds the authenticity token to each request when needed - used in conjunction with
// <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
$(document).ajaxSend(function(event,request,settings){
if (typeof(AUTH_TOKEN) == "undefined") return;
settings.data = settings.data || "";
settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});
// Setup some common information (which can be overridden)
$.ajaxSetup({
dataType: 'script',
type: 'post'
});
// ---------------------------------------------------------------------- //
// Watch over all links with class of 'delete_content',
// remove the /delete portion of the url, send via ajax, and return false
$(function() {
$("a.delete_content").bind("click",function(e){
link = this.href.replace(/\/delete$/, '');
$.ajax({ url: link,
data: {'_method':'delete'}});
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment