rails4.0 session activerecord
Active Record Session Store
A session store backed by an Active Record class. A default class is provided, but any object duck-typing to an Active Record Session class with text session_id and data attributes is sufficient.
Installation
Include this gem into your Gemfile:
gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
Run the migration generator:
rails generate active_record:session_migration
Then, set your session store in config/initializers/session_store.rb:
Foo::Application.config.session_store :active_record_store
Configuration
The default assumes a sessions tables with columns:
id(numeric primary key),session_id(string, usually varchar; maximum length is 255), anddata(text or longtext; careful if your session data exceeds 65KB).
The session_id column should always be indexed for speedy lookups. Session data is marshaled to the data column in Base64 format. If the data you write is larger than the column's size limit, ActionController::SessionOverflowError will be raised.
You may configure the table name, primary key, and data column. For example, at the end of config/application.rb:
ActiveRecord::SessionStore::Session.table_name = 'legacy_session_table'
ActiveRecord::SessionStore::Session.primary_key = 'session_id'
ActiveRecord::SessionStore::Session.data_column_name = 'legacy_session_data'
Note that setting the primary key to the session_id frees you from having a separate id column if you don't want it. However, you must set session.model.id = session.session_id by hand! A before filter on ApplicationController is a good place.
Since the default class is a simple Active Record, you get timestamps for free if you add created_at and updated_at datetime columns to the sessions table, making periodic session expiration a snap.
You may provide your own session class implementation, whether a feature-packed Active Record or a bare-metal high-performance SQL store, by setting
ActionDispatch::Session::ActiveRecordStore.session_class = MySessionClass
You must implement these methods:
self.find_by_session_id(session_id)initialize(hash_of_session_id_and_data, options_hash = {})attr_reader :session_idattr_accessor :datasavedestroy
The example SqlBypass class is a generic SQL session store. You may use it as a basis for high-performance database-specific stores.
http://rubydoc.info/gems/activerecord-session_store/0.1.0/frames
rails4.0 session activerecord的更多相关文章
- 解决rails4.0中send_file文件下载两次的问题
之前在开发文件下载的功能时,我遇到了一个很奇怪的问题,点击下载链接,在chrome console中会出现两次请求,第一次返回200,下载的数据缓存在chrome的cache中,第二次返回304,直接 ...
- asp.net 2.0 Session丢失问题
可行的解决方法(本人已用): 1.Web.config文件修改sessionstate模式(默认为InProc) <sessionState mode="/> 2.开启ASP.N ...
- cas4.0 session中返回更多的用户信息
实现思路: 新增AccoutAttributeDao类继承StubPersonAttributeDao,重写getPerson方法.实际应用中我们只需要修改getPersion方法中的内容,根据实际情 ...
- 远程线程注入突破SESSION 0
远程线程注入突破SESSION 0 SESSION 0 隔离 在Windows XP.Windows Server 2003,以及更老版本的Windows操作系统中,服务和应用程序使用相同的会话(Se ...
- ruby -- 进阶学习(三)Strong Parameters在rail3.0和4.0中的区别
今天coding的时候遇到一个未知的类型,于是用puts logo_params.class查了下数据类型,然后google了一下发现是 Strong Parameter Strong paramet ...
- rails 4.0.2 + mongoid 对mongodb进行增删改查
新建项目 rails new mongoid_app --skip-active-record --skip-test-unit --skip-bundle create create README. ...
- ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value:
今天碰到一个相当棘手的问题,那就是ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value . 本来在本地测试是没有任 ...
- zookeeper源码分析之六session机制
zookeeper中session意味着一个物理连接,客户端连接服务器成功之后,会发送一个连接型请求,此时就会有session 产生. session由sessionTracker产生的,sessio ...
- Openfire的启动过程与session管理
说明 本文源码基于Openfire4.0.2. Openfire的启动 Openfire的启动过程非常的简单,通过一个入口初始化lib目录下的openfire.jar包,并启动一个 ...
随机推荐
- Lintcode 375.克隆二叉树
-------------------------- 水题 AC代码: /** * Definition of TreeNode: * public class TreeNode { * public ...
- Selenium通过WebDriver控制IE浏览器出错 Browser zoom level was set to 109%. It should be set to 100%
错误信息: WebDriverException: Message: Unexpected error launching Internet Explorer. Browser zoom level ...
- EF不能很好的支持DDD?估计是我们搞错了!
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:最近在ABP项目中尝试纯粹的DDD,然后遇到EF实现的Repository似乎不能很好 ...
- JAVA基础(一)
1.Java class中的static修饰的成员表面其属于该类所共有,而不是属于某个实例.static修饰的成员不能直接调用非static修饰的成员. 2.Java构造器不能定义返回类型,也不能使用 ...
- vim 基本使用
vim 下基本命令 重新加载 .vimrc source ~/.vimrc 列出当前缓冲区的所有文档 ls 然后使用 b+编号 移至该文档 选中多行 v + shift 然后 j k 上下移动 缩进单 ...
- js控制刷新后回到页面原来位置
1.document.location.reload(); 2.http://www.jb51.net/article/99749.htm
- RadioButton(单选按钮)文字在按钮的左边
<RadioButton style="@style/CustomCheckboxTheme" android:layout_width="fill_parent& ...
- 使用GizwitsOpenAPI,快速开发轻应用
导读:使用机智云提供的Open API(Http / WebSocket),可以快速开发网页或微信应用等基于html的轻应用,用于管理和控制智能设备.机智云 Open API 主要帮助开发者通过 HT ...
- windowsservice
1.创建 windows服务 项目 文件 -> 新建项目 -> 已安装的模板 -> Visual C# -> windows ,在右侧窗口选择"windows 服务 ...
- VBA实例收集
1.工作表事件:固定制定区域激活,使之不能选择其他区域. Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target. ...