Thursday, May 29, 2008

AssociationFu Revisted with jQuery

I've been really enjoying jQuery. It implements a mean iterator that I thought prototype.js should have implemented. Instead of this in prototype.js:


array_object.each(function(e){ e.do_something })


you can do this in jQuery:


array_object.do_something


That's flippin' great. You can also do chained calls:


array_object.do_something.do_something_else


But the biggest thing is that jQuery is great for unobstrusive javascript. I now design and implement forms to work without javascript then I enable javascript and use jQuery to attach to the various form elements and instant AJAXy goodness.

So I've gone back to AssociationFu to rip out all the RJS stuff and design the controller and model to handle submission of the form to add new association objects and remove association objects on submission of the form.

But then I thought, "Why rip the RJS out?" It works, so leave it in and just add helper functions to create 'add' buttons and 'remove' check boxes. Cool! I had to add a controller module to handle the form submission but it doesn't seem like much work. I've yet to test it all but it seems to have come together nicely.