我如何在Rails 3中的reset_session命令后找到新的session_id



我在这里使用命令"reset_session"来避免会话固定。

运行命令后,我想将新生成的session_id存储在数据库中,但没有定义session[:session_id]。

我写了一个简单的测试:
class ApplicationController < ActionController::Base
  protect_from_forgery
  after_filter :after_test
  def after_test
    RAILS_DEFAULT_LOGGER.debug "Old Session: #{session.inspect}"
    reset_session
    session[:random_number] = ((rand*1000).to_i)
    RAILS_DEFAULT_LOGGER.debug "New Session: #{session.inspect}"
  end
end

连续加载两个页面的日志结果为:

Started GET "/" for 127.0.0.1 at 2011-04-16 11:42:57 +0200
Processing by WelcomeController#index as HTML
Rendered welcome/index.html.erb within layouts/application (1.9ms)
Old Session: {"random_number"=>519, "session_id"=>"d17df62e286f20bd25e2714ee4f58020", "_csrf_token"=>"NkD5ZjG/RYLolfRy0ADmr+h+Sp2TXEOQlc6HhNpyp/g="}
New Session: {:random_number=>172}
Completed 200 OK in 7ms (Views: 6.4ms | ActiveRecord: 0.0ms)

Started GET "/" for 127.0.0.1 at 2011-04-16 11:42:58 +0200
Processing by WelcomeController#index as HTML
Rendered welcome/index.html.erb within layouts/application (2.0ms)
Old Session: {"random_number"=>172, "session_id"=>"54f46f520c80044a9f5475af78a05502", "_csrf_token"=>"9skbBEN35jQYRgH9oQVz1D5Hsi/o9l7fm7Qx9XDNETc="}
New Session: {:random_number=>497}
Completed 200 OK in 7ms (Views: 6.4ms | ActiveRecord: 0.0ms)

你可以看到随机数(172)被正确地传递到第二页,但是新会话没有显示新的会话id。

我认为新的会话id("54f46f520c80044a9f5475af78a05502")是在"after_filter"之后生成的,但我不知道如何检索它。

是的,rails有这个问题。有票- https://rails.lighthouseapp.com/projects/8994/tickets/2200-session-support-broken

正如你所看到的,它还没有解决。

相关内容

  • 没有找到相关文章

最新更新