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: stack level too deep Extracted source (around line #1): 1: <p><%= @unit.id %></p> 2: <p><%= @unit.description %></p> 3: I''ve found this ticket dating back to 2006 that seems to report a similar problem: http://dev.rubyonrails.org/ticket/6035 Any idea other than adopting a different session option ? Many thanks in advance. Bruno --------------------------------- model unit.rb class Unit < ActiveRecord::Base end controller unit_controller.rb class UnitController < ApplicationController def index if session[:currentUnit] @unit = session[:currentUnit] else @unit = Unit.find(:first) session[:currentUnit] = @unit end end end view index.rhtml <p><%= @unit.id %></p> <p><%= @unit.description %></p> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Rudy Jacobs
2008-May-10 17:24 UTC
Re: ActiveRecord and memory_store sessions error
Brubix wrote:> --------------------------------- > model unit.rb > class Unit < ActiveRecord::Base > end > > controller unit_controller.rb > class UnitController < ApplicationController > > def index > if session[:currentUnit] > @unit = session[:currentUnit] > else > @unit = Unit.find(:first) > session[:currentUnit] = @unit > end > end > > end > > view index.rhtml > <p><%= @unit.id %></p> > <p><%= @unit.description %></p>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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---