1

I need to set session variable on ajax call on rails. I have following ajax code:

         $.ajax({
              url: '/dashboard/set_session',  
              type: 'GET',
               data: {
                  site_id: site_id
              },
              dataType : 'json'
          }).done(function(data){
            console.log(data);
            });

And on rails end:

    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

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.

How to fix this issue?

Sandesh Sharma
  • 1,064
  • 5
  • 16
  • 32

0 Answers0