title: how to set session variable with ajax request on rails?
body: <p>I need to set session variable on ajax call on rails. I have following ajax code:</p>
  
  <pre><code>         $.ajax({
                url: '/dashboard/set_session',  
                type: 'GET',
                 data: {
                    site_id: site_id
                },
                dataType : 'json'
            }).done(function(data){
              console.log(data);
              });
  </code></pre>
  
  <p>And on rails end:</p>
  
  <pre><code>    def set_session
        puts params[:site_id]
        session[:site_id] = params[:site_id]
        puts session[:site_id] 
        respond_to do |format|
          format.json { render json: 'success'}
        end
      end
  </code></pre>
  
  <p>The first and second puts print same value. That means the session is set. But when I navigate to other pages or reload the page, the session value of site_id is cleared.</p>
  
  <p>How to fix this issue?</p>