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 <tr><td class="dc-form-label"> <label for="record_password">Password:</label></td> <td class="dc-form-field"> <input id="record_password" type="password" size="20" name="record[password]"></td> </tr> <tr> <td class="dc-form-label"> <label for="record_password_confirmation">Password confirmation:</label></td> <td class="dc-form-field"> <input id="record_password_confirmation" type="password" size="20" name="record[password_confirmation]"></td> </tr> ----------------------------- 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sep 14, 2012, at 7:31 AM, Damjan Rems wrote:> 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 > <tr><td class="dc-form-label"> > <label for="record_password">Password:</label></td> > <td class="dc-form-field"> > <input id="record_password" type="password" size="20" > name="record[password]"></td> > </tr> > > <tr> > <td class="dc-form-label"> > <label for="record_password_confirmation">Password > confirmation:</label></td> > <td class="dc-form-field"> > <input id="record_password_confirmation" type="password" size="20" > name="record[password_confirmation]"></td> > </tr> > ----------------------------- > 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> Help please. > > by > TheR > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
> This may be related: > http://reservedwords.herokuapp.com/words/records?q[word_or_notes_cont]=record > > WalterNope. I checked by TheR -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 14 September 2012 12:31, Damjan Rems <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 > <tr><td class="dc-form-label"> > <label for="record_password">Password:</label></td> > <td class="dc-form-field"> > <input id="record_password" type="password" size="20" > name="record[password]"></td> > </tr> > > <tr> > <td class="dc-form-label"> > <label for="record_password_confirmation">Password > confirmation:</label></td> > <td class="dc-form-field"> > <input id="record_password_confirmation" type="password" size="20" > name="record[password_confirmation]"></td> > </tr> > ----------------------------- > 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> > Help please. > > by > TheR > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law wrote in post #1076008:> Have you remembered to add the password_digest field to the table? > > ColinHave 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Attached is the generated html source code. Thanks for any help TheR Attachments: http://www.ruby-forum.com/attachment/7745/myuser_form.html -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.