aris
September 14, 2012, 1:31pm
1
I am trying to set password with bcrypt-ruby and mongoid but whatever I
do I get “Password digest can’t be blank”.
Model
class User
include Mongoid::Document
include Mongoid::Timestamps
include ActiveModel::SecurePassword
field :first_name, type: String, default: ‘’
field :last_name, type: String, default: ‘’
field :password_digest, type: String
has_secure_password
attr_accessible :name, :password, :password_confirmation
end
Form part
Password:
Password
confirmation:
-----------------------------
I have tried a lot. Funny thing is that editing or adding user with
rails console works OK.
One possible problem is that I have my own form system and I always use
name “record” for table name (instead of user in the case).
Help please.
by
TheR
ther
September 14, 2012, 1:37pm
2
On Sep 14, 2012, at 7:31 AM, Damjan R. wrote:
field :last_name, type: String, default: ‘’
<input id=“record_password” type=“password” size=“20”
-----------------------------
I have tried a lot. Funny thing is that editing or adding user with
rails console works OK.
One possible problem is that I have my own form system and I always use
name “record” for table name (instead of user in the case).
This may be related:
http://reservedwords.herokuapp.com/words/records?q[word_or_notes_cont]=record
Walter
ther
September 14, 2012, 3:47pm
4
On 14 September 2012 12:31, Damjan R. [email protected] wrote:
field :last_name, type: String, default: ‘’
<input id=“record_password” type=“password” size=“20”
-----------------------------
I have tried a lot. Funny thing is that editing or adding user with
rails console works OK.
One possible problem is that I have my own form system and I always use
name “record” for table name (instead of user in the case).
I don’t understand, do you mean the the code you have shown is not
your actual code? It is always better to copy/paste your code in case
of typos.
Have you remembered to add the password_digest field to the table?
Colin
ther
September 15, 2012, 3:50am
5
Everything looks fine with your model/controller. The problem is
probably coming from your view. Could you please include the full
snippet form in the view please?
ther
September 17, 2012, 7:44am
6
Attached is the generated html source code.
Thanks for any help
TheR
ther
September 14, 2012, 7:36pm
7
Colin L. wrote in post #1076008:
Have you remembered to add the password_digest field to the table?
Colin
Have you even tried to look at the code supplied ;-(
Code represents a simplified model that I run test on and it also does
not work. I don’t think that adding few pages of code would be of any
help.
by
TheR
ther
October 19, 2012, 2:34pm
8
It turned out the problem was in controller code.
ActiveModel::SecurePassword implements password= method, which is used
to set password_digest field.
so: calling record.password= sets password_diggest field.
But as I have written I am using my own form system, which uses single
controller for editing all models. I had something like this in the
controller:
fields.each do |k,v|
@record [v[‘name’]] = params[‘record’][v[‘name’]]
end
which leads to when v is ‘password’
@record [‘password’] = params[‘record’][‘password’]
which works perfectly OK with mongoid and adds password attribute to
document.
And of course doesn’t call @record.password= method at all.
Solution is to use send(“password=”, value) method of @record .
@record.send ( “#{v[‘name’]}=”, params[‘record’][v[‘name’]] )
Hope this will save somebodies hours in future.
by
TheR