// public/javascripts/application.js
jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

jQuery.fn.submitPostWithAjax = function() {
  this.click(function() {
    $.post($(this).attr('href'), "_method=post", null, "script");
    return false;
  })
  return this;
};

jQuery.fn.submitPutWithAjax = function() {
  this.click(function() {
    $.post($(this).attr('href'), "_method=put", null, "script");
    return false;
  })
  return this;
};

jQuery.fn.submitDeleteWithAjax = function() {
  this.click(function() {
    $.post($(this).attr('href'), "_method=delete", null, "script");
    return false;
  })
  return this;
};

jQuery.fn.submitFormWithAjax = function() {
  this.submit(function() {
    $.post(this.action, $(this).serialize(),  null, "script");
    return false;
  })
  return this;
};

$(document).ready(function() {
  $(".accept").submitPutWithAjax();
})

$(document).ready(function() {
  $(".decline").submitDeleteWithAjax();
})

$(document).ready(function() {
  $("#new_comment").submitFormWithAjax();
})