1
我的Rails應用程序中有三個模型。如下所述,用戶可以有更多的電話和電話可以屬於更多的客戶。Rails has_many:通過關聯表輸入
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
以客戶的形式,當用戶可以插入更多手機時,需要輸入文本,用逗號分隔。提交表格時,數據應插入三個數據庫表格中:客戶數據到客戶表格,電話到電話表格以及客戶和電話之間的關聯到額外表格。 我怎麼能創建這樣一個表單?
試試cocoon gem https://github.com/nathanvda/cocoon – Saqib