【发布时间】:2016-03-01 12:29:01
【问题描述】:
我的 Rails 应用程序中有三个模型。如下所述,用户可以拥有更多的手机,手机可以属于更多的客户。
class Customer < ActiveRecord::Base
has_many :customer_phone_associations, dependent: :destroy
has_many :phones, through: :customer_phone_associations
end
class Phone < ActiveRecord::Base
has_many :customer_phone_associations
has_many :customers, through: :customer_phone_associations
end
class CustomerPhoneAssociation < ActiveRecord::Base
belongs_to :customer
belongs_to :phone
end
在客户的表格中,当用户可以插入更多电话时,我需要文本输入,用逗号分隔。提交表单时,数据应插入三个数据库表:客户数据到客户表、电话到电话表以及客户和电话之间的关联到额外表。 我怎样才能创建这样的表格?
【问题讨论】:
标签: ruby-on-rails ruby