- Insert it into the link
- Pass it as data
--
Route
As you've attempted already, you could pass it in the route itself:
# app/assets/javascript/verifying_link.js
$(document).on("click", ".element", function(){
$.ajax({
url: "/verify_link/"+id+"&table_row="+row
});
});
The way to do this is to include the id from your HTML.
Your ajax will no doubt be triggered by an event. The event will correspond to an HTML element, which can now have data, or id attributes (thanks to HTML5):
#app/views/controller/view.html.erb
<%= link_to "Your Link", path_to_link, id: @item.id %>
#app/assets/javascript/verifying_link.js
$(document).on("click", ".element", function(){
var id = $(this).attr("id");
$.ajax({
url: "/verify_link/"+id,
});
});
You'd need to make sure you pass the data to JS from HTML to make this work
Data
Alternatively (and this will only work on collection routes), you could send the id in the data tag. Of course, this will not do anything to help you include your id in your JS, but it's still very important:
#app/assets/javascript/verifying_link.js
$(document).on("click", ".element", function(){
var id = $(this).attr("id");
$.ajax({
url: "/verify_link",
data: { id: id }
});
});
The difference here is that if you wanted include other data, you could include it in the data attribute. Further, you'll want to make sure that your routes correspond to what you're looking to send as data (IE member routes will need to have the id appended to the URL)