![](/img/trans.png)
[英]Rails: NameError in Devise::SessionsController#create
[英]NameError in Devise::SessionsController#create
我正在嘗試使用:lockable
,所以當我將其添加到class User < ActiveRecord::Base
並嘗試登錄或登錄時。 我得到重定向到錯誤頁面。 這就是我得到的
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
有任何想法嗎? 當我刪除:lockable
,一切正常
設計需要datetime :locked_at
字段。 你一定錯過了。
更新:
包括此遷移,因為看起來您的user
表中沒有適當的字段。
做這個
rails g migration add_devise_required_missing_fields
打開生成的遷移文件並將其粘貼
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
最后,運行rake db:migrate
有兩個可能的錯誤,
您可能會錯過啟用需要設計可鎖定功能的字段的機會
##可鎖
#t.integer:failed_attempts,默認值:0,null:false#僅當鎖定策略為:failed_attempts時
#t.string:unlock_token#僅當解鎖策略為:email或:both時
#t.datetime:locked_at
換句話說,您必須啟用並遷移User(如果您對用戶模型應用了devise)表中所需的這三個輸入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.