【发布时间】:2018-03-03 00:15:12
【问题描述】:
我在一些模型之间有一个has_many :through 关联,它决定了哪些数据集在某些仪表板上可见。
class Dashboard < ActiveRecord::Base
has_many :dashboard_datasets
has_many :datasets, :through => :dashboard_datasets
end
class DashboardDataaset < ActiveRecord::Base
belongs_to :dashboard
belongs_to :dataset
end
class Dataset < ActiveRecord::Base
has_many :dashboard_datasets
has_many :dashboards, :through => :dashboard_datasets
end
用于创建新Dashboard 的表单有一组名为dataset_ids[] 的简单复选框,允许您选择要在该仪表板上显示的预先存在的数据集。
class DashboardForm < Reform::Form
model: :dashboard
property :name
property :description
collection :dataset_ids
end
到目前为止,一切都很简单......
但是,我现在希望向连接表添加一个额外的关联,以确定应该用于给定仪表板上的该数据集的“布局”。即网格,表格,列表。等等
class Layout < ActiveRecord::Base
has_many :dashboard_datasets
end
class DashboardDataaset < ActiveRecord::Base
belongs_to :dashboard
belongs_to :dataset
belongs_to :layout
end
我现在想调整我的仪表板表单,以便除了复选框之外,对于选中的每个数据集复选框,都有一个选择框供我选择要在此给定关联上使用的布局。
我从哪里开始?扩展表单对象上的collection 使其更丰富并包含更多信息?
非常感谢任何建议。
【问题讨论】:
标签: ruby-on-rails reform trailblazer