I need to pass a variable which is captured from client side via jquery to controller, so that it can be used in the server side. After googling a bit, I found that we can pass it via an Ajax call.
routes.rb
get "mymethod?Id=", :to => "sample#mymethod"
j1.js
$(function(){
var test = 1;
$(.btn).click(function(){
$.ajax({
url: '/mymethod?Id='+ test,
success: function(data) {
}
});
});
});
sample_controller.rb
def mymethod
session[:Id] = params["Id"];
end
When I try to use session[:Id], it is always nil.
Any ideas,
Thanks