Has anyone managed to replace ActiveRecordStore::Session with their
own model?
In the source (http://dev.rubyonrails.org/browser/trunk/actionpack/lib/
action_controller/session/active_record_store.rb) it says you can
override the default by setting
CGI::Session::ActiveRecordStore.session_class = MySessionClass
I have tried doing this in a number of ways but I get all kinds of
weird errors, as varied as the methods I’ve tried.
Before you shoot me down for trying to do something I shouldn’t let me
explain why I want to do this.
I’d like a session model that looks something like:
class Session < ActiveRecord::Base
has_many :product_viewings, :dependent => :destroy
has_many :products, :through => :product_viewings, :limit =>
10, :include => :image
belongs_to :order
belongs_to :user
end
In my controller I would like to do something like
session.model.user = @user
and
@recently_viewed_products = session.model.products
Because I cannot replace ActiveRecordStore::Session with my session
class above I have to do instead:
session.model.user_id = @user.id
and
@recently_viewed_products =
Session.find_by_session_id(session.session_id).products
I don’t think it’s unreasonable to want to treat session.model as a
first class ActiveRecord model, anything else just seems a bit half-
baked.
Any ideas on how I could make this happen would be greatly
appreciated.
Paul Odeon