title: "Restful" resources in rails: session[:user_id] = user.id syntax when session is a resource but not a model
body: <p>Working through authentication in RailsCasts, there was <a href="http://railscasts.com/episodes/250-authentication-from-scratch-revised" rel="nofollow">one</a> where I didn't understand something completely fundamental and important (it's pro, sorry - you need to be subscribed to access it).</p>
  
  <p>He creates a user model with an email and encrypted password (has_secure_password).</p>
  
  <p>Then he makes a new controller called Sessions, and declares it as a resource in the config. i.e. </p>
  
  <pre><code>resources :sessions
  </code></pre>
  
  <p>Then, inside the sessions controller, he defines the create method like this:</p>
  
  <pre><code>user = find user and authenticate
  if user
      session[:user_id] = user.id
  else ...
  </code></pre>
  
  <p>But sessions as a model doesn't exist. For instance, if I open up my console and write</p>
  
  <pre><code>sessions[:user_id] = "hello"
  </code></pre>
  
  <p>it throws. Does anyone have an explanation or a link to this very basic concept that I'm missing?</p>
  
  <p>Thanks!</p>
  
  <p>Edit: Thanks Sanfor. Typo fixed, also for markup plus most importantly an answer!</p>