I'm having a problem with sessions in rails 3.2 when I use mongoid as SessionStore. I decided to use Brian Hempel's fork of mongo_session_store
gem, as it was updated last month.
Before switching to this gem, I was using the default cookie-based session store, and it was working without problem. But now, even flash
doesn't work when I redirect to another page. Session data seems to be reset on every single request.
And as a side-question: every request creates a new session document in db! Is it right? I'm confused. =(
I put these lines in my Gemfile:
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
gem 'bson_ext', "~> 1.5"
gem 'mongo_session_store-rails3', '~> 3.0.5'
Then in my config/initializers/session_store.rb
:
SomeAppName::Application.config.session_store :mongoid_store
sessions_controller.rb:
class SessionsController < ApplicationController
def new
...
end
def create
user = User.find_by_identifier(params[:identifier])
if user && user.authenticate(params[:password])
session[:uid] = user._id
redirect_to root_url, :notice => "Logged in!"
else
flash.now.alert = "Invalid email or password"
render :new
end
end
def destroy
...
end
end
If any other part of my code is needed, please tell me to post it. Thanks in advance.