Changeset 866
- Timestamp:
- 03/06/05 23:34:03 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/session/active_record_store.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r862 r866 1 1 *SVN* 2 3 * Changed ActiveRecordStore to use Marshal instead of YAML as the latter proved troublesome in persisting circular dependencies. Updating existing applications MUST clear their existing session table from data to start using this updated store #739 [Jamis Buck] 2 4 3 5 * Added shortcut :id assignment to render_component and friends (before you had to go through :params) #784 [Lucas Carlson] trunk/actionpack/lib/action_controller/session/active_record_store.rb
r639 r866 4 4 require 'cgi' 5 5 require 'cgi/session' 6 require 'base64' 6 7 7 8 # Contributed by Tim Bates 8 9 class CGI 9 10 class Session 10 # Active Record databasebased session storage class.11 # Active Record database-based session storage class. 11 12 # 12 13 # Implements session storage in a database using the ActiveRecord ORM library. Assumes that the database 13 14 # has a table called +sessions+ with columns +id+ (numeric, primary key), +sessid+ and +data+ (text). 14 # The session data is stored in the +data+ column in YAML format; the user is responsible for ensuring that 15 # only data that can be YAMLized is stored in the session. 15 # The session data is stored in the +data+ column in the binary Marshal format; the user is responsible for ensuring that 16 # only data that can be Marshaled is stored in the session. 17 # 18 # Adding +created_at+ or +updated_at+ datetime columns to the sessions table will enable stamping of the data, which can 19 # be used to clear out old sessions. 20 # 21 # It's highly recommended to have an index on the sessid column to improve performance. 16 22 class ActiveRecordStore 17 23 # The ActiveRecord class which corresponds to the database table. 18 24 class Session < ActiveRecord::Base 19 serialize :data20 # Isn't this class definition beautiful?21 25 end 22 26 … … 31 35 def initialize(session, option=nil) 32 36 ActiveRecord::Base.silence do 33 @session = Session.find_by_sessid(session.session_id) || Session.new("sessid" => session.session_id, "data" => {})34 @data = @session.data37 @session = Session.find_by_sessid(session.session_id) || Session.new("sessid" => session.session_id, "data" => marshalize({})) 38 @data = unmarshalize(@session.data) 35 39 end 36 40 end … … 53 57 def restore 54 58 return unless @session 55 @data = @session.data59 @data = unmarshalize(@session.data) 56 60 end 57 61 … … 59 63 def update 60 64 return unless @session 61 ActiveRecord::Base.silence { @session.update_attribute "data", @data}65 ActiveRecord::Base.silence { @session.update_attribute "data", marshalize(@data) } 62 66 end 67 68 private 69 def unmarshalize(data) 70 Marshal.load(Base64.decode64(data)) 71 end 72 73 def marshalize(data) 74 Base64.encode64(Marshal.dump(data)) 75 end 63 76 end #ActiveRecordStore 64 77 end #Session