javascript - Can someone help me dissect what is wrong with my Rails PUT ajax request? -


i don't have experience ajax other few 1 shots on rails app , post requests i'm having serious problems on how make ajax request put method. i'm having problems passing in rail's @variables controller through ajax.

i have view code below:

 - if logged_in? && @account.stacks.count > 0     - @account.stacks.each |stack|     - haml_tag :div, stack.title     = check_box_tag 'stacked', 0, false, { stack: stack.id, project: @project.id }  

this creates html tags pictured below:

enter image description here

this .js code below:

$(document).ready(function() {    // grab checked value 0 unchecked, 1 checked   var check_value = $("input[name='stacked']").val();    $("input[name='stacked']").click(function() {     if (check_value == 0) {        //grab id of stack object       var stack_id = $("input[name='stacked']").attr("stack");        //change unchecked value checked       check_value = 1;        //make request controller       // url = '/stacks/12345'       $.ajax("/stacks/" + stack_id,{         type: "put"         datatype: ?         //success: function change html element on modal       });       } else {       // code code code     }   }); }); 

when try send off request see if works. error.

started put "/stacks/undefined" ::1 @ 2015-06-02 15:12:28 -0400 processing stackscontroller#update */*   parameters: {"id"=>"undefined"} 

why url stacks/undefined? console.logged url , returns correct string? attempted pass in data attributes specified in rails guides doesn't seem work either.

= check_box_tag 'stacked', 0, false, { "data-stack" => stack.id, "data-project" => @project.id }  var stack_id = $("input[name='stacked']").data("stack"); 

the url tends end /stacks/<#object>. isn't right either. can pinpoint i'm doing wrong?


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -