Brandon Cordell
Brandon Cordell

Reputation: 1318

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?

Upvotes: 0

Views: 276

Answers (1)

apneadiving
apneadiving

Reputation: 115521

Simply add:

attr_accessor :password_confirmation

Upvotes: 2

Related Questions