Upgrading :with parameter on a link_to_remote in Rails 3
What's the preferred UJS replacement for the Rails RJS helper ':with' parameter on a link_to_remote when upgrading to Rails 3 (using the new unobtrusive link_to... :remote => true syntax).
eg. Replacemen开发者_JS百科t for:
link_to_remote "Ajax Call", example_path(@thing), :with => "'foo=' + $('field').val()"
Specifically, I'm looking into a link that sends a put request using ajax with the value of a select option to update some other field in a form.
What's the nicest unobtrusive way to do this?
I've found this thread but I resolved it in another way. If you already have a link with data-remote => true
you can do the following:
$(document).on('ajax:before', selector_to_your_link, function() {
$(this).data('params', params_that_you_want_to_send);
});
As a temporary measure I've added a small hack to the jquery.rails.js file:
line 34 changed from:
var data = el.is('form') ? el.serializeArray() : [];
to
var data = el.is('form') ? el.serializeArray() : eval(el.attr('with'));
However the obtrusive js remains...
精彩评论