你能告诉我如何在rails3应用程序中使用外部活动记录会话存储吗?
在rails2中,它很简单
ActiveRecord::SessionStore::Session.establish_connection("sessions_#{RAILS_ENV}")但是rails3呢?
发布于 2010-08-27 08:49:36
查看activerecord-3.0.0.rc/lib/active_record/session_store.rb的源代码,我看到了以下内容:
165 # The database connection, table name, and session id and data columns
166 # are configurable class attributes. Marshaling and unmarshaling
167 # are implemented as class methods that you may override.
183 # :singleton-method:
184 # Use the ActiveRecord::Base.connection by default.
185 cattr_accessor :connection
208 def connection
209 @@connection ||= ActiveRecord::Base.connection
210 end所以,你应该能够这样做:ActiveRecord::SessionStore::Session.connection = establish_connection("sessions_#{RAILS_ENV}"),但我还没有测试过。
您还可以从同一个文件创建自己的会话类,以便更好地控制连接到数据库的方式:
34 # You may provide your own session class implementation, whether a
35 # feature-packed Active Record or a bare-metal high-performance SQL
36 # store, by setting
37 #
38 # ActiveRecord::SessionStore.session_class = MySessionClass
39 #
40 # You must implement these methods:
41 #
42 # self.find_by_session_id(session_id)
43 # initialize(hash_of_session_id_and_data)
44 # attr_reader :session_id
45 # attr_accessor :data
46 # save
47 # destroy发布于 2011-02-10 02:56:40
在config/initializers/session_store.rb中查找
注释掉关于使用:cookie_store的行
取消注释底部有关使用:active_record_store的行
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
MyApp::Application.config.session_store :active_record_store注意:"MyApp“将是您的应用程序的名称。
发布于 2010-08-27 06:17:34
你得用这个。
Rails.application.config.session_store :active_record_store不过,我不确定如何设置表名。
https://stackoverflow.com/questions/3579890
复制相似问题