jQuery CRUD deletion patterns
July 22nd, 2008
0 comments
Like a lot of rubyists, I've been playing with jQuery and lov'in it. Here is a little pattern I've been using to generically handle ajax deletion of resources through jQuery.
How are you doing this? Is there a better, cleaner or simpler way?
// ajaxify CRUD delete links
$('a.crud_delete_link').livequery('click', function(){
if (!confirm('Are you sure?'))
return false
var self = this
$.ajax({
// window.location.href should be ok most of the time unless the resource is nested...
// in that case use the rel attribute
url: $(self).attr('rel') != '' ? $(self).attr('rel') : window.location.href,
data: { _method: 'delete' },
type: 'POST',
success: function() {
if ($(self).hasClass('hide_li')) {
$(self).parents('li').fadeOut('fast')
} else {
// trim off record identifer and return to "index" page or refresh page
// example: /admin/clusters/1 => /admin/clusters
// example: /account/logo => /account/logo
var parts = window.location.pathname.match(/^(.*)\/(\d+)$/)
window.location = (parts == null) ? window.location : parts[1]
}
}
})
return false
})

Hacking with the master
July 22nd, 2008
2 comments

All Articles
-
Rails migrations for large text columns
05/24/08 1 comment -
Nathan Walker Chandler
05/10/08 1 comment -
acts_as_quickbooks_model
05/02/08 -
Ruby XML Parsing Benchmarks
04/23/08 5 comments -
QuickBooks Integration Plugin moves to GitHub
04/18/08 -
TrustCommerce gem moves to github
03/31/08 2 comments -
Recurring Billing with TrustCommerce
03/18/08 2 comments -
Squawk Micro - micro blogging engine
02/16/08 -
Yoga - one year later
02/16/08 -
ActionWebService with Rails 2.0
12/13/07 1 comment -
to_xml with filtering
12/09/07 -
ActiveRecord find_by shortcut
12/04/07 -
Video demo of QuickBooks integration plugin
10/17/07 -
QuickBooks Integration Plugin
10/16/07 4 comments -
Web designer needed
09/10/07 -
TrustCommerce payment history & invoicing
08/28/07 9 comments -
Perfect Rails Stack... part deux
06/14/07 3 comments -
Taking Merb for a Spin
05/31/07 5 comments -
Happy birthday
05/19/07 1 comment -
Geek of the Month
05/15/07 1 comment -
Hpricot fun
05/07/07 1 comment -
Rails and QuickBooks Online Integration - Part 1
05/03/07 1 comment -
Yoga on Rails
04/18/07 4 comments -
Avoiding scoping pitfalls
04/11/07 -
Auto-focusing Rails helpers
04/09/07 1 comment -
Quick tip - assert_toggled
03/15/07 1 comment -
Tumblring along...
03/09/07 -
Quick tip - Generating long strings for testing
03/09/07 2 comments -
Service Sidekick refresh
03/07/07 -
Auto-params plugin
03/05/07 -
TrustCommerce gem released
02/28/07 -
Working with Rails Interview
02/20/07 -
TrustCommerce Subscription plugin updated
02/09/07 7 comments -
Rails and Google Apps / Gmail Integration
02/02/07 -
Logo and site refresh
02/01/07 -
Rdoc with external resources
01/28/07 2 comments -
RESTful Product Tracker
01/19/07 8 comments -
Rails and QuickBooks integration - Part 4
12/14/06 2 comments -
Rails and QuickBooks integration - Part 3
12/13/06 6 comments -
Rails and QuickBooks integration - Part 2
12/12/06 1 comment -
Rails and QuickBooks integration - Part 1
12/07/06 4 comments -
Trackplace launches!
11/20/06 -
Quick tip - Flexible session sweeping
11/10/06 -
Quick tip - Coercing subdomains in Rails
11/06/06 -
Web design lessons from a developer
11/04/06 -
TrustCommerce Subscription plugin updated
10/31/06 -
Quick tip - Markdown with hard breaks
10/25/06 3 comments -
TrustCommerce Subscription plugin released
10/20/06 6 comments

