我在使用 rails+mongoid 时遇到了一些问题,以节省操作创建
我写了关系:
class SchoolClass
include Mongoid::Document
include Mongoid::MultiParameterAttributes
has_one :teachers
field :nome, type: String
validates_presence_of :nome, :message => 'Nao pode ser vazio'
end
和
class Teacher
include Mongoid::Document
include Mongoid::MultiParameterAttributes
belongs_to :school_class
field :nome
field :nascimento, :type => Date
field :email
field :senha
end
我正常创建了学校课程。
显示学校课程:
<%= f.input :school_class, :collection => SchoolClass.all, label_method: "nome", include_blank: false %><br />
教师控制器是:
def create
@teacher = Teacher.new(params[:teacher])
respond_to do |format|
if @teacher.save
format.html {redirect_to(teachers_path, :notice => 'Professor cadastrado com sucesso')}
format.json { head :no_content }
else
format.html {render :action => :new}
format.json { render json: @teacher.errors, status: :unprocessable_entity }
end
end
end
我不知道如何保存参考。浏览器给我这个:
uninitialized constant SchoolClas
任何人都可以帮助我吗?