Skip to content

Instantly share code, notes, and snippets.

@tubbo
Forked from factore/gist:2997298
Created June 26, 2012 17:36
Show Gist options
  • Select an option

  • Save tubbo/2997310 to your computer and use it in GitHub Desktop.

Select an option

Save tubbo/2997310 to your computer and use it in GitHub Desktop.
respond_to :html, :js
def destroy
@student = User.find(params[:id])
if @student.destroy
render json: { student: @student, student_id: dom_id(@student) }
else
render nothing: true
end
end
$(function () {
$('.delete-student').on('click', function (event) {
event.preventDefault();
var $link = $(this);
if (confirm("You sho bout that?")) {
$.ajax({
type: 'DELETE'
url: $link.attr('href'),
success: function (response) {
console.log("Test if this is actually firing"); // Not logging to the console.
$(response.student_id).hide(); // Hide the deleted record.
$link.fadeOut();
}
});
}
});
});
= link_to student_path(s), :class => "btn btn-mini btn-danger delete-student", :method => "delete", :confirm => "Are you sure you want to delete this student?", :remote => "true", :title => "Delete Student" do
%i.icon-remove
@jwreagor
Copy link

Github activity feed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment