Jason DiCioccio
2005-Apr-03 05:13 UTC
ActiveRecordStore with latest rails and actionpack releases
Greetings, I have just installed rails/actionpack from gems. After using the default PStore for a while, I decided to try using ActiveRecordStore to store my session data. I have the table created correctly and everything. However, the issue is that I get the following error now when attemping to load anything through rails: (partial traceback) [Sat Apr 02 23:49:02 EST 2005] Dispatcher failed to catch: undefined method `fin d_by_sessid'' for CGI::Session::ActiveRecordStore::Session:Class (NoMethodError) /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.9.1 /lib/active_record/base.rb :770:in `method_missing'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.9.1 /lib/active_record/base.rb :770:in `each'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.9.1 /lib/active_record/base.rb :770:in `method_missing'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.7.0 /lib/action_controller/sessi on/active_record_store.rb:37:in `initialize'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.7.0 /lib/action_controller/sessi on/active_record_store.rb:36:in `silence'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.7.0 /lib/action_controller/sessi on/active_record_store.rb:36:in `initialize'' /usr/local/lib/ruby/1.8/cgi/session.rb:273:in `new'' /usr/local/lib/ruby/1.8/cgi/session.rb:273:in `initialize'' Any help would be appreciated.. Thanks in advance! Jason DiCioccio _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jeremy Kemper
2005-Apr-03 05:24 UTC
Re: ActiveRecordStore with latest rails and actionpack releases
Jason DiCioccio wrote:> I have just installed rails/actionpack from gems. After using the > default PStore for a while, I decided to try using ActiveRecordStore to > store my session data. I have the table created correctly and > everything. However, the issue is that I get the following error now > when attemping to load anything through rails: > > (partial traceback) > > [Sat Apr 02 23:49:02 EST 2005] Dispatcher failed to catch: undefined > method `fin > d_by_sessid'' for CGI::Session::ActiveRecordStore::Session:Class > (NoMethodError)Your sessions table doesn''t have a sessid column.> Any help would be appreciated..What''s your sessions table look like? PostgreSQL: create table sessions ( id serial primary key, sessid char(32) unique, data text, created_at timestamp not null, updated_at timestamp ); created_at and updated_at are optional, but they''re updated for free by Active Record and nice to have for selectively clearing stale sessions. jeremy
Jason DiCioccio
2005-Apr-03 05:30 UTC
Re: ActiveRecordStore with latest rails and actionpack releases
Wow.. I feel dumb. I could have sworn I checked this specifically. However, I named my table ''session'' instead of sessions.. Sorry about that :) Regards, -JD-
Peter-Frank Spierenburg
2005-Apr-03 06:15 UTC
Re: ActiveRecordStore with latest rails and actionpack
>What''s your sessions table look like? PostgreSQL: > > create table sessions ( > id serial primary key, > sessid char(32) unique, > data text, > created_at timestamp not null, > updated_at timestamp > ); > >created_at and updated_at are optional, but they''re updated for free by >Active Record and nice to have for selectively clearing stale sessions. > >Is this in the docs somewhere? This would be a very useful feature for my application. Besides id, created_at, and updated_at, what field names have special properties? Peter.
Jeremy Kemper
2005-Apr-03 07:50 UTC
Re: ActiveRecordStore with latest rails and actionpack
Peter-Frank Spierenburg wrote:>> created_at and updated_at are optional, but they''re updated for free by >> Active Record and nice to have for selectively clearing stale sessions. >> > Is this in the docs somewhere? This would be a very useful feature for > my application. Besides id, created_at, and updated_at, what field names > have special properties?Timestamping callbacks are set up by default for columns named created_at/created_on and updated_at/updated_on. See http://rails.rubyonrails.com/classes/ActiveRecord/Timestamp.html Callbacks let you set up "triggers" like this easily. You can reimplement timestamping yourself: class Foo < ActiveRecord::Base before_create { |foo| foo.created_at = Time.now } before_save { |foo| foo.updated_at = Time.now } end Wonderful! Now say we want timestamps in our other models. Let''s make a module to mix in the behavior: module Timestamped # Invoked when "include Timestamped" is called in base_class. def self.append_features(base_class) base_class.before_create { |model| model.created_at = Time.now } base_class.before_save { |model| model.updated_at = Time.now } end end class Foo < ActiveRecord::Base include Timestamped end Then say this is so useful we''d like to add it to any models with these columns: module Timestamped def self.append_features(base) base.before_create do |model| model.created_at ||= Time.now if model.respond_to?(:created_at) end base.before_save do |model| model.updated_at = Time.now if model.respond_to?(:updated_at) end end end class ActiveRecord::Base include Timestamped end Best, jeremy
Peter-Frank Spierenburg wrote:> >> created_at and updated_at are optional, but they''re updated for free by >> Active Record and nice to have for selectively clearing stale sessions. >> >> > Is this in the docs somewhere? This would be a very useful feature for > my application. Besides id, created_at, and updated_at, what field names > have special properties?Besides timestamping, there is optimistic locking(lock_version), and single table inheritance(type), as well as a few other field names that have special purposes. The wiki[1] has references to the relevant API docs for each 1. http://wiki.rubyonrails.com/rails/show/MagicFieldNames -- Lee