2016-03-30 64 views
0

我很好奇为什么sessionrake db:drop后还活着?db:drop后rails仍然活着

def current_order 
    if !session[:order_id].nil? 
    @current_order = Order.find(session[:order_id]) 
    else 
     Order.new 
    end 
    end 
    helper_method :current_order 

和耙分贝后:放弃它给了我异常

Couldn't find Order with 'id' = my session number 
>> session[:order_id] 
=> 11 

这意味着会话仍然存在。但为什么?

+1

你在数据库中存储会话?默认情况下,我认为他们使用cookies存储 – tpbowden

+0

正确@tpbowden。 CookieStore一直是Rails 2以来的默认版本。http://guides.rubyonrails.org/security.html#session-storage – max

+0

@tpbowden no我不会在db中保存会话,而不是如何使用rake db删除会话:reset? – user

回答

1

Rails默认使用ActionDispatch::Session::CookieStore来存储会话。因此,清理数据库不会删除客户端持有的任何会话数据。

取而代之,您将删除浏览器中的cookies(正在开发中)或更改密钥库以使现有Cookie无效。

请参见:

+0

如何在服务器端做到这一点?除了'config/secrets.yml'中的更改 – user

+0

除了通过将会话存储机制更改为“ActionDispatch :: Session :: CookieStore”之外的其他方法,AFAIK没有其他方式。为了生产,你可以改变'ENV [“SECRET_KEY_BASE”]而不是YAML文件。 – max

相关问题