如何在Ruby on Rails应用程序中使用活动记录会话?

时间:2021-04-30 07:33:43

I'm running into a CookieOverflow error, so I want to switch to database sessions.

我遇到了CookieOverflow错误,因此我想切换到数据库会话。

In config/environment.rb:

Uncommented: config.action_controller.session_store = :active_record_store
Changed:  :secret for config.action_controller.session

In application.rb:

Uncommented: protect_from_forgery :secret => 'ac44a970c0047c1b049c1967986af674'

I ran some 'rake ...' commands it told me to, and it created this database table:

我运行了一些'rake ...'命令告诉我,它创建了这个数据库表:

CREATE TABLE `sessions` (
`id` int(11) NOT NULL auto_increment,
`session_id` varchar(255) NOT NULL,
`data` text,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
PRIMARY KEY  (`id`),
KEY `index_sessions_on_session_id` (`session_id`),
KEY `index_sessions_on_updated_at` (`updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Now, that seems all good and done. BUT it never writes any sessions to the database. Logins still work though. What else do I have to do to make this work? How is this even working if it's using active record sessions and not writing any session data to the database...?

现在,这看起来一切都很好。但它永远不会将任何会话写入数据库。登录仍然有效。我还需要做些什么来完成这项工作?如果它使用活动记录会话而不是将任何会话数据写入数据库,那么它是如何工作的?

Is there an easy way to step through/troubleshoot this?

是否有一种简单的方法可以逐步完成/排除故障?

1 个解决方案

#1


0  

Make sure that you don't have cookie sessions enabled in development.rb (or whatever environment you're running this in). After that, please post your sessions controller.

确保您没有在development.rb中启用cookie会话(或者您正在运行此任何环境)。之后,请发布会话控制器。

#1


0  

Make sure that you don't have cookie sessions enabled in development.rb (or whatever environment you're running this in). After that, please post your sessions controller.

确保您没有在development.rb中启用cookie会话(或者您正在运行此任何环境)。之后,请发布会话控制器。