【发布时间】:2017-06-18 14:33:32
【问题描述】:
我有 2 个模型:Department 和 Station。 Station 有 3 种不同的enum 类型。用户应该可以使用复选框选择 1、2 或 3 个不同类型的电台。如果选择了电台,则应在Station 中创建一条记录。
知道怎么做吗?
换句话说,应该是这样的:
class Department < ApplicationRecord
has_many :stations, dependent: :destroy
class Station < ApplicationRecord
enum type: { type1: 0, type2: 1, type3: 2 }
belongs_to :department
_form.rb should be something like this:
= f.association :stations, :as => :check_boxes, :collection => Station.types.keys
当然应该不一样。
【问题讨论】:
标签: ruby-on-rails enums relationship