1
の作成中にUser
を作成するのにを使用しようとしています。私の問題は、入れ子になったUser
情報が無効であっても、Organization
が(有効な情報を持っていると仮定して)作成されていることです。Mongoidは子が無効な場合に親を保存することを承諾します
私のモデルは次のようになります。
class Organization
include Mongoid::Document
attr_accessible :name, :users_attributes
field :name, :type => String
has_many :users, dependent: :destroy
accepts_nested_attributes_for :users, :limit => 1
validates_presence_of :name
end
class User
include Mongoid::Document
authenticates_with_sorcery!
attr_accessible :email, :password, :password_confirmation
field :email, type: String
validates_confirmation_of :password, :if => :password
validates_presence_of :password, :on => :create
validates :password, :length => { :minimum => 6 }
validates_presence_of :password_confirmation, :if => :password
validates_presence_of :email
validates_uniqueness_of :email
belongs_to :organization
end
だから基本的に、私は、有効な組織と無効なユーザーに渡します。最終的には、ユーザー情報が無効であるにもかかわらず、組織が適切に作成されます。思考?