简体   繁体   中英

Using Rails form helpers with Mongoid

I'm trying to build a new Rails app with MongoDB using Mongoid as the ORM. The authentication is handled by the sorcery gem.

I'm getting the following error in my Users#new view.

undefined method 'password_confirmation' for #<User:0x007feff2a23890>

My model looks like this.

class User                                                                                                                                                              
 include Mongoid::Document                                                                                                                                             
 authenticates_with_sorcery!                                                                                                                                           

 attr_accessible :username, :email, :password, :password_confirmation                                                                                                  

 field :username                                                                                                                                                       
 field :email                                                                                                                                                          
 field :password                                                                                                                                                       
end

I get this error if I don't have a field definition in the model for each field. The password_confirmation field is a virtual field, so it shouldn't have a field definition anyway. How do I use dynamic and virtual fields in Mongoid (which are set to true in the config) with form helpers?

只需添加:

attr_accessor :password_confirmation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM