Ich versuche, einen Iphone-Benutzer in der Lage sein, eine Schule und mehrere Administratoren gleichzeitig zu erstellen. Allerdings, wenn ich versuche, die Schule mit verschachtelten Attribute speichern es gibt die Fehler admins ist ungültigSpeichern geschachtelter Attribute in Mongoid-Dokument in Schienen api
Schule Modell
class School
include Mongoid::Document
include Mongoid::Timestamps
# Callbacks
after_create :spacial
embeds_many :admins
accepts_nested_attributes_for :admins
validates_associated :admins
# Fields
field :school_name, type: String
end
Admin Modell
class Admin
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :school
before_create :generate_authentication_token!
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
Schulen-Controller
class Api::V1::SchoolsController < ApplicationController
def show
respond_with School.find(params[:id])
end
def create
school = School.new(school_params)
admin = school.admins.build
if school.save
render json: school, status: 201, location: [:api, school]
else
render json: { errors: school.errors }, status: 422
end
end
private
def school_params
params.require(:school).permit(:school_name, admins_attributes: [:email, :password, :password_confirmation])
end
end
Parameter
Parameters: {"school"=>{"school_name"=>"Curry College", "admins_attributes"=>{"0"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}}, "subdomain"=>"api"}