问题描述:

I have a custom User model with lots of rows. I have a password_digest column that I want to keep. (it comes from has_secure_password)

And I also want to use Devise database authenticatable, but from my limited knowledge on Devise, I have to use the encrypted_password column.

Is there a way to trick Devise into using my current password_digest for authentication, so I don't lose all my User passwords?

If I add an encrypted_password column it will be blank and I definitely don't want it to stay like that.

I'm probably thinking about this the wrong way. What's the right way to solve this?

网友答案:

Simply write a migration to rename the column name, it will not loose your data.

 rails g migration ChangeColumnName

this will generate a migration file

class ChangeColumnName < ActiveRecord::Migration
    def change
       rename_column :users, :password_digest, :encrypted_password
    end
end
相关阅读:
Top