Kamil Kukura
2005-Aug-08  07:40 UTC
storing an object into the session causes framework to freeze
I have defined my own class such as:
class Filter
    attr_accessor :office
    attr_reader :office_list
    
    def initialize(pf)
        @office = pf ? pf[:office].to_i : 0
        @office_list = Office.find_all.collect { |o| [ o.name, o.id ] }
    end
    
    def conditions
        @office > 0 ? [''office_id=?'', @office] :
''TRUE''
    end
end
It is used for filtering a list of records and works quite well in this usage:
    if params[:filter]
        @filter = Filter.new(params[:filter])
        session[:current_filter] = @filter
    else
        @filter = session[:current_filter] || Filter.new(nil)
    end
If passed from params, it is created and stored in the session for subsequent
use. Otherwise it is restored from the session or created as an empty filter.
Problem is, it''s working only in given controller. As soon as
there''s action in
other controller, the framework enters infinite loop somewhere and only hard
stop and restart can be done afterwards.
-- 
Kamil
Kamil Kukura
2005-Aug-09  07:22 UTC
Re: storing an object into the session causes framework to freeze
Problem solved. The class Filter has been defined within controller''s class. In development environment it is probably unloaded so session''s object couldn''t be instantianted back to its (suddenly non-existent) class. If only there would be an exception raised instead of going into looping.