It seems that memory_store sessions have problems storing ActiveRecord
objects.
The following test application work perfectly with the standard
session option (Rails 2.0.2) but if I add
config.action_controller.session_store = :memory_store
to envirnment.rb, I get the following error when I refresh the page:
SystemStackError in Unit#index
Showing unit/index.rhtml where line #1 raised:
I don't think you want to be storing the whole object to session.
def index
if session[:current_unit_id]
@unit = Unit.find(session[:current_unit_id])
else
@unit = Unit.find(:first)
session[:current_unit_id] = @unit.id
end
end
but you'd probably prefer to do it with a before_filter.
Thank you for your answer.
Could you please illustrate it in a little more detail ?
In the real application I'm working on, changes to the current unit
may occur in more than one user interaction and are not necessarily
comitted to the db at the end of work.
Of course I can switch to a different session engine (what I already
did) or change the application logic but still my questions are:
- is this the expected behavior of the :memory_store or is it a bug ?
- is there something I should check or set to change this behavior ?