Rails教程 - >如何“使用会话而不是cookie”(第8章,练习2)

时间:2012-06-28 20:41:11

标签: ruby-on-rails-3 railstutorial.org

我对第8章,练习2:

感到困惑
Use session instead of cookies so that users are automatically signed out when they close
their browsers.

在这里和github进行讨论,看来完成此任务的方法是修改SessionsController,如下所示:

def create
  user = User.find_by_email(params[:session][:email])
  if user && user.authenticate(params[:session][:password])
...

但是当我这样做时,我再也无法登录了:

NoMethodError in SessionsController#create
undefined method `[]' for nil:NilClass

我需要修改哪些内容才能使用session而不是Cookie进行身份验证?

1 个答案:

答案 0 :(得分:-1)

线索出现在错误NoMethodError in SessionsController#create

#there表示SessionsController中的create方法。