→ jQuery and respond_to

Thursday, December 13, 2007

I’ve fallen in love with jQuery. Facebox is all jQuery, as is FamSpam. Anyway, here’s how to get jQuery working with Rails’ respond_to:


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

Just throw that at the bottom of your application.js and you’re good to go: all jQuery ajax requests will trigger the wants.js block of your respond_to declaration, exactly like you’d expect. Enjoy.