On Fri, Jun 19, 2009 at 11:44 AM, Nicholas Van
Weerdenburg<[email protected]> wrote:
>  "I never use remote_form_for, since unobtrusive JS works even better"
> Why do you find that? I assume you without the block form helpers as well in
> that case?

I just use "form_for()" instead of "remote_form_for()". If I want to
use AJAX, I'll throw some jQuery into the page. Something like:

function handle_success(data) {
  // do whatever we want
}

$('form.new_comment').submit(function(e) {
  e.preventDefault();

  var $form = $(this);
  var url = $form.attr('action');
  var data = $form.serialize();

  $.ajax({
    type: 'POST',
    url: url,
    data: data,
    success: handle_success
  });
});

Benefits:
- No JavaScript in views
- No JavaScript in controllers
- Graceful degradation if JavaScript is disabled
- Easier to customize behavior (with remote_form_for(), you're
encouraged to only update certain elements)
- No 500-character-long remote_form_for() calls
- Better error handling ($.ajax() lets you define error handlers; I do
not know whether remote_form_for() does)
- Nicer HTML output

My main beef with Rails's Prototype helpers (or their jRails
equivalents) is that they don't really open the world of JavaScript up
to you. When you define behavior explicitly, you suddenly have much
more control, customizations are easier, and, with the proper JS
architecture, you end up writing less code. More maintainable code.
More understandable code. Etc.

But all of this has nothing to do with Haml, except that it lets you
avoid Haml's icky multi-line syntax in remote_form_for() calls,
because you can avoid remote_form_for() calls entirely.

Adam

-- 
My Website: http://adamhooper.com
My Blog: http://adamhooper.com/blog

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to