[英]NameError in Devise::SessionsController#create
I'm trying to use :lockable
, and so when I add it to class User < ActiveRecord::Base
and try to sign in or log in . 我正在尝试使用
:lockable
,所以当我将其添加到class User < ActiveRecord::Base
并尝试登录或登录时。 I get redirect to and error page. 我得到重定向到错误页面。 Here's what I get
这就是我得到的
NameError in Devise::SessionsController#create
undefined local variable or method `locked_at' for #<User:0x000001025a56d8>
Rails.root: /Users/user/Ruby
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"dsfgsgfddsfgt5467657654n74=",
"user"=>{"email"=>"email@email.com",
"password"=>"[FILTERED]"},
"commit"=>"Sign in"}
Toggle session dump
Toggle env dump
Response
Headers:
None
Any ideas? 有任何想法吗? When I remove
:lockable
it all works fine 当我删除
:lockable
,一切正常
Devise requires datetime :locked_at
field. 设计需要
datetime :locked_at
字段。 You must missed it. 你一定错过了。
UPDATE: 更新:
Include this migration as it looks like you dont have appropriate field in your user
table. 包括此迁移,因为看起来您的
user
表中没有适当的字段。
do this 做这个
rails g migration add_devise_required_missing_fields
Open the generated migration file and paste this 打开生成的迁移文件并将其粘贴
change_table(:users) do |t| ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts t.string :unlock_token # Only if unlock strategy is :email or :both t.datetime :locked_at end add_index :users, :unlock_token, unique: true
lastly , run rake db:migrate
最后,运行
rake db:migrate
There is two possible mistakes, 有两个可能的错误,
You may missed to enable the fields which need devise lockable feature 您可能会错过启用需要设计可锁定功能的字段的机会
## Lockable ##可锁
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts #t.integer:failed_attempts,默认值:0,null:false#仅当锁定策略为:failed_attempts时
# t.string :unlock_token # Only if unlock strategy is :email or :both #t.string:unlock_token#仅当解锁策略为:email或:both时
# t.datetime :locked_at #t.datetime:locked_at
You have to enable and migrate, in other word, these three inputs needed in User(if you applied devise to User model) table. 换句话说,您必须启用并迁移User(如果您对用户模型应用了devise)表中所需的这三个输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.