Question

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. Replacement 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?

Was it helpful?

Solution 2

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...

OTHER TIPS

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);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top