title: storing session in rails api application
body: <p>I have a rails api only application <code>[config.api_only = true]</code> in which I enable the cookies through these following lines:</p>
  
  <p>in application.rb:</p>
  
  <pre><code>config.middleware.insert_after ActionDispatch::ParamsParser, ActionDispatch::Cookies
  config.middleware.insert_after ActionDispatch::ParamsParser, ActionDispatch::Session::CookieStore
  </code></pre>
  
  <p>in application_controller.rb</p>
  
  <pre><code>include ActionController::Helpers
  include ActionController::Cookies
  </code></pre>
  
  <p>I also added secret_token.rb as follows:</p>
  
  <pre><code>Rails.application.config.secret_token = 'token'
  </code></pre>
  
  <p>in my controller, I am trying to store the session like this:</p>
  
  <pre><code>def index
      #other codes
      session[:userid] = useridstring
      render :text =&gt; session[:userid]
  end
  </code></pre>
  
  <p>Note: however, after executing this in chrome, I am examining the cookie and none is set...</p>
  
  <p>then in the same controller, but in another action, I am trying to read the session like this:</p>
  
  <pre><code>def readsession
      userId = session[:userid]
      render :text =&gt; userId
  end
  </code></pre>
  
  <p>and nothing is rendered.. :(</p>
  
  <p>Is there anything I missed?</p>
  
  <p>I tried following the answer <a href="https://stackoverflow.com/a/15363386/474330">here</a> which suggest that I set <code>config.api_only = false</code>, however the result is the same (I have no cookie set, and when read in another controller, session is still empty</p>
  
  <p>Sorry that it is such a basic question (or initial configuration matter), I am still very new in ruby and rails..</p>