I have a task to make knockout.js using ruby ββon rails. I want to send javascript value to controller. My index.html.erb
<%= javascript_include_tag "knockout-2.2.0","country-state" %> <table> <thead> <tr> <th>Country</th> <th>State</th> <th> </th> </tr> </thead> <tbody data-bind='foreach: lines'> <tr> <td> <select data-bind='options: sampleProductCategories, optionsText: "country", optionsCaption: "Select...", value: category'> </select> </td> <td data-bind="with: category"> <select data-bind='options: products, optionsText: "country", optionsCaption: "Select...", value: $parent.product'> </select> </td> <td> <a href='#' data-bind='click: $parent.removeLine'>Remove</a> </td> </tr> </tbody> </table> <button data-bind='click: addLine'>Add</button> <button data-bind='click: save'>Submit</button> <script> $(document).ready(function() { function formatCurrency(value) { return "$" + value.toFixed(2); } var CartLine = function() { var self = this; self.category = ko.observable(); self.product = ko.observable(); self.subtotal = ko.computed(function() { return self.product() ? self.product().price * parseInt("0" + self.quantity(), 10) : 0; }); </script>
In the terminal, it looks like
Started GET "/employees/1?undefined=undefined" for 127.0.0.1 at Mon Jan 21 13:36:15 +0530 2013 Processing by EmployeesController#show as JSON Parameters: {"id"=>"1", "undefined"=>"undefined"}
How to send selected state and country to controller as json object?
source share