I have a link_to
with remote:
set to true. What I want to do is add an extra attribute with the request so I tried it with this:
<script>
$(document).ready(
function(){
$("#part_btn").bind("ajax:beforeSend",
function(event, xhr, settings, data){
settings.data += "&user_id=5"
})
})
</script>
Now I don't even know if this is possible because the user_id
is never sent to the controller and when I log the setting.data
I get null&user_id=5
.
If it's not possible like this, is there any other way to do it?
EDIT:
I didn't add an extra parameter to the link_to
because the user_id actually comes from a select tag and I wanted to add the selected value as extra data like this:
settings.data += ("&user_id="+$("#register_user_id option:selected").val());
this is what my link_to
looks like:
<%= text_field_tag :part_id, nil, :class => 'text_field', data: {source: autocomplete_parts_for_registers_registers_path} %>
<%= link_to('toevoegen', '#!', id: 'part_btn', class: 'btn btn-small btn-success addbtn', style: "margin-top: 5px", data: {source: add_part_registers_path}, remote: true) %>