【发布时间】:2011-07-17 14:59:29
【问题描述】:
我正在使用 Ruby on Rails 3,我想在 Rack 中间件中使用 cookies.signed 方法。我需要它,因为我想直接在中间件中对用户进行身份验证,而不是在 application_controller.rb 文件中使用 before_filter。
例如,如果我以这种方式在控制器中使用该方法:
cookies.signed[:user_id']
我明白了
---
- 1 # This is the id of the current signed in user
- a64ee3asdtjhcc7b35fcb280956be00ba27f94d48dfe4291c06db7d57577d5893 # This is the cookie salt
但如果我以这种方式在(同一应用程序的)机架中间件中使用它:
request = Rack::Request.new(env)
request.cookies.signed[:user_id']
我明白了
NoMethodError
undefined method `signed' for #<Hash:0x00000103333d40>
那么,如何才能在中间件中使用该方法?如何获取用户 ID 以便进行身份验证?
也许我必须包括\扩展,例如,ActionDispatch...如果是这样,如何?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 cookies rack