Created
November 11, 2008 09:21
-
-
Save joshk/23787 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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