0
我有一个使用STI从用户模型继承的学生模型。用户型号has_one profile
。从表单创建新学生时,学生管理员的创建操作成功生成了学生模型的实例以及学生个人资料的实例,可以通过@student.profile
进行检查。在这个阶段,student.id,profile.id和profile.user_id都是零。在rails 4下,我可以执行@ student.save,并且学生和相关模型都将被保存。然而,在导轨5,@ student.save返回false,并显示一条错误消息如何保存与rails的关联5
:"profile.user"=>["can't be blank"]
如何保存@student实例凭借其在轨5联想?
相关的代码是
def create
@student = build_student(params[:student])
if @student.save