Session getting destroyed when ajax call is made in rails application -
i have ruby on rails site. applicationcontroller looks like
class applicationcontroller < actioncontroller::base protect_from_forgery before_filter :handle_cookie default_marketplace = 1 def handle_cookie if (session[:isimpersonation].nil?) puts "initilized 0" session[:isimpersonation] = 0 end end
i initializing variable isimpersonation in session object if nil. when normal request made (i.e non-ajax) variable initialized 1 time once i.e. session object retains variable isimpersonation.
but when create ajax phone call like:
$.ajax({ url : "/a/fetch", type : "post", info : { rundate : $('#rundate_select :selected').val(), id : idval, mp : mpval }, beforesend : function(xhr) { xhr.setrequestheader('x-csrf-token', $('meta[name="csrf-token"]') .attr('content')); }, success : function(data) { var $elem = $('<div>').html(data); $("#overall").html( $elem.find('#overall').html()); }, error : function(data) { } });
during ajax phone call variable in session re-initialized. searched , followed post: rails not reloading session on ajax post.
but, not working me. thought missing?
finally, got working. missing:
<%= csrf_meta_tags %>
in tag of layout file i.e. application.html.erb
ruby-on-rails ruby-on-rails-3 session
No comments:
Post a Comment