【发布时间】:2019-06-20 18:05:38
【问题描述】:
我已经阅读了 Rails 中的嵌套属性,到目前为止,我发现 gems cocoon 有我需要为嵌套属性分发表单并且可以完成到目前为止的所有实现。但我想通过使用 Cocoon 搜索产品数据,尝试将现有数据产品作为嵌套属性添加到发票表单中。我应该怎么做才能在 Rails 中完成这些表单交互?
就像这张图片我猜的例子: image
更新
发票.rb
class Invoice < ApplicationRecord
has_many :products, inverse_of: :invoice
accepts_nested_attributes_for :ticket_details, reject_if: :all_blank, allow_destroy: true
end
产品.rb
class Product < ApplicationRecord
belongs_to :category
belongs_to :tax
belongs_to :invoice
end
【问题讨论】:
-
你应该提供一些你的代码,例如:你的模型
-
嗨,我已经更新了我的代码模型
标签: javascript ruby-on-rails ruby postgresql nested-attributes