Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: manipulate link_to remote POST query string parameters

I have the following link_to method:

link_to "", votes_path(vote: { post_id: post.id, up: true}), method: :post, remote: true

and I'm trying to intercept the triggered AJAX call to manipulate the POST parameters. With a GET request this was quite easy because the parameters are stored under data:

$('#my_link').bind('ajax:before', function() {
  $(this).data('params', { foo: 'bar' })
});

but that's not the case for POST request. Can someone tell me where the POST parameters are stored?

like image 651
Mexxer Avatar asked Nov 27 '25 16:11

Mexxer


1 Answers

Nevermind I just found out myself.

What you have to do is just manipulate the href attribute from the first object in the link array:

$('#my_link').bind('ajax:before', function() {
  $(this).first().attr('href', href + "&vote[custom_param]=customvalue");
});
like image 86
Mexxer Avatar answered Nov 30 '25 12:11

Mexxer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!