Skip to content

Instantly share code, notes, and snippets.

@factore
Created June 26, 2012 17:34
Show Gist options
  • Select an option

  • Save factore/2997298 to your computer and use it in GitHub Desktop.

Select an option

Save factore/2997298 to your computer and use it in GitHub Desktop.
# Controller
respond_to :html, :js
# DELETE /users/1
def destroy
@student = User.find(params[:id])
@student.destroy
respond_with(@student)
rescue Exception => ex
logger.warn('ERROR: ' + ex.message)
render :nothing => true
end
# destroy.js.erb
console.log("Test if this is actually firing"); // Not logging to the console.
$('#<%= dom_id(@student) %>').hide(); // Hide the deleted record.
# View.haml
= 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
# students.js
$(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 () {
$link.fadeOut();
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment