首页 > 解决方案 > 嵌套表单的解决方案

问题描述

我一直在这个问题上停留了一段时间。

需要使用自定义输入为比赛 类别制作表格。它应该从Information表中获取所有值并构建输入,但棘手的部分是它应该保存到Category_informations表中。

class Competition < ApplicationRecord
  has_many :categories
  has_many :informations
end

class Category < ApplicationRecord
  belongs_to :competetion
  has_many :category_informations
  has_many :information, through: competition
end

class CategoryInformation
  belongs_to :catagory
  belongs_to :information
end

class Information < ApplicationRecord
  belongs_to :competetion
  has_many :category_informations
end

比赛 -> 名称

类别 -> 名称,competition_id

信息 -> 名称,competition_id

类别信息 -> 值、类别 ID、信息 ID

标签: ruby-on-rails

解决方案



推荐阅读