I am new to Jquery. Have a problem when passing parameter to Jquery function.
My application has nested resources.
class Post < ActiveRecord::Base
has_many :votes
And route is
sort_votes_post POST /posts/:id/sort_votes(.:format) posts#sort_votes
Sortable function is
$(function() {
$("#sortable").sortable({
update: function() {
$.ajax({
type: 'post',
data: $('#sortable').sortable('serialize'),
url: '/posts/[not sure how to pass :id here]/sort_votes'})
}
});
$("#sortable").disableSelection();
});
No idea how to pass :id to the url option.
If your code is in the asset pipeline I’m not sure you can because pipeline is precompiled so any dynamic details won’t work.
It’s a little hacky but I’d suggest passing a variable from the view so add before your application.js is added
then in js