Reputation:
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 . 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
Upvotes: 2
Views: 2045
Reputation: 329
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.string :unlock_token # Only if unlock strategy is :email or :both
# 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.
Upvotes: 0
Reputation: 8132
Devise requires datetime :locked_at
field. You must missed it.
UPDATE:
Include this migration as it looks like you dont have appropriate field in your user
table.
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
Upvotes: 1