Reputation: 113
I have commented everything out of my model except:
has_secure_password
and with my migration I have added:
t.string "password_digest"
to my users database.
When I create a user in the rails console and try to save it however, the password doesn't encrypt. It appears in my database as the password that I entered. Could someone please tell me how to get has_secure_password to encrypt my password? Am I missing something simple? I have the bcrypt gem installed.
Upvotes: 2
Views: 1564
Reputation: 1
t.string :password_digest
perhaps rollback your migration and place this in your migration file. I hope this helps.
Upvotes: 0
Reputation: 2993
In case anyone else gets here with a different problem. We were trying to use this with ember (à la http://www.thegreatcodeadventure.com/jwt-authentication-with-rails-ember-part-i-rails-knock/ ) and our problem was (pretty much the same as the answerers indicated above) that we added passwordDigest
to our ember data model (so we were essentially assigning to password_digest
rather than password
, but ember data was doing it on our behalf so we didn't realize it at first from the answers above).
Upvotes: 0
Reputation: 601
Yes. For others that come by this post and aren't quite sure what you mean.
You don't assign a password to password_digest
You assign it to password
When you add has_secure_password to your model, it automatically adds a virtual attribute called password. When you assign a value to password, it will encrypt and save into password_digest.
Upvotes: 9
Reputation: 113
ANSWERED: I needed to use the virtual password attribute not the password_digest attribute
Upvotes: 0