rails 3, using Devise, how add :lockable after the

2019-02-21 10:52发布

问题:

I am using devise successfully, but decided to add the :lockable module. Our table is called Users.

I cannot find docs on how to add a new devise module (or remove one) after doing an initial setup.

回答1:

You should be able to do the following in a migration

change_table(:users) do |t|
  t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
end

The fields it adds are:

t.integer  "failed_attempts",                     :default => 0
t.string   "unlock_token"
t.datetime "locked_at"


回答2:

Devise adds a call to devise in your model app/models/user.rb in your case. You can just add :lockable as a parameter to that.