微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rails 5,选择一个子模型作为嵌套属性数据必须保存在数据库中

如何解决Rails 5,选择一个子模型作为嵌套属性数据必须保存在数据库中

我有这样的代码。 // student_performances_controller.rb

 def new
    @student_performance = StudentPerformance.new
    @student_performance.course_performances.build
    @student_performance.mock_performances.build
  end

params.require(:student_performance).permit(:student_id,:course_id,:performance_type,:date,:mock_performances_attributes => [:id,:mock_practicle],:course_performances_attributes => [:id,:video_completion])

// student_performance.rb

accepts_nested_attributes_for :mock_performances,allow_destroy: true,:reject_if => :all_blank

accepts_nested_attributes_for :course_performances,:reject_if => :all_blank

学生表现 课程表现 模拟性能
学生姓名 student_performance_id student_performance_id
日期 cousre_completion 模拟练习

我想构建嵌套的表单属性,我尝试使用学生表现和模拟表现模型,如果我在学生表现中使用课程表现和模拟表现,则在提交任何一个模型(CP 或 MP)时,其他模型都会抛出验证错误。如何构建这种类型的表单取决于性能类型选择需要提交该对象的嵌套属性

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。