Rails 3个额外的会话配置选项(key,expires_after,secure)

有人可以指出新的Rails 3.x会话配置选项是什么?

我正在尝试复制我在Rails 2.3.x应用程序中的相同配置。

这是我在应用程序中使用的配置:

#environment.rb config.action_controller.session_store = :active_record_store config.action_controller.session = { :key => '_something', #non-secure for development :secret => 'really long random string' } # production.rb - override environment.rb for production config.action_controller.session = { :key => '_something_secure', :secret => 'really long random string', :expire_after => 60*60,#time in seconds :secure => true #The session will now not be sent or received on HTTP requests. } 

但是,在Rails 3.x中,我只能提到以下内容:

 AppName::Application.config.session_store :active_record_store AppName::Application.config.secret_token = 'really long random string' AppName::Application.config.cookie_secret = 'another really long random string' 

是否有其他配置设置来控制密钥,expire_after时间和安全选项?

关于后者,如果在production.rb中设置“config.force_ssl = true”,我认为不再需要安全选项?

非常感谢!

您现在可以通过初始化程序配置基于Cookie的会话存储,可能在config/initializers/session_store.rb 。 在Rails 3中,会话存储是一个中间件,配置选项通过一次调用config.session_store传入:

 Your::Application.config.session_store :cookie_store, :key => '_session' 

你可以在hash中添加你想要的任何额外选项:key ,例如

 Your::Application.config.session_store :cookie_store, { :key => '_session_id', :path => '/', :domain => nil, :expire_after => nil, :secure => false, :httponly => true, :cookie_only => true } 

(这些只是标准默认值)

如果你在生产中强制使用SSL,那么在cookie上设置secure不应该在实践中真正有所作为,但是你可能想要设置它只是为了安全起见……

 Your::Application.config.session_store :cookie_store, { :key => '_session_id', :secure => Rails.env.production? }