4Nov/091
RoR: Session / login management
This is basic yet not obvious in Ruby on Rails - I've been looking for info on this for a long time (a long time for this problem is anything more than 5 minutes).
So, this is the way you make sessions/logins work in ruby:
class SessionController < ApplicationController
def login
@session['logged'] = true
end
def logout
@session['logged'] = false
end
end
The @session variable is available anywhere. Use it anywhere. For example you could come up with the following view showing whether the user is logged in:
<p>Logged in: <%= @session['logged'] %> </p>
And that is it. Anything beyond that (like adding a User model etc.) is out of this post's target. There are many articles on those things yet no clear explanation where to find and how to init a session. As you can see - the answer is clear - you don't
The session is already there. Just start using it.