Here is the problem i\'m stuck on. I want to pass the javascript variables to the rails controller.
Ajax code in jQuery:
$("#submit_button").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get values from elements on the page: */
var mdate = $('#mdate').val();
var phone = $('#phone').val();
/* Send the data using post and put the results in a div */
$.ajax({
url: "/BookCreate/?mdate="+mdate+"&phone="+phone,
type: "post",
data: values,
success: function(){
alert('Saved Successfully');
},
error:function(){
alert('Error');
}
});
});
Routes : ( As I am assuming your controller name is book )
match '/BookCreate', to: 'book#create'
For this you have to add jquery file to your code or this link