我有2个模型Invoice
和Payement
定义如下:
class Invoice < ApplicationRecord
has_many :invoicings
has_many :payements, through: invoicings
accepts_nested_attributes_for: :payements
attr_accessor :old_payement_number
attr_accessor :payement_type
enum payement_type: [ :new, :old ]
end
class Payement < ApplicationRecord
has_many :invoicings
has_many :invoices, through: :invoicings
end
我使用简单形式的Cocoon来创建嵌套表单并且它工作得非常好,但我想添加一些内容,我想在父表单中添加一个附加字段,其中包含访问者old_payement_number
和{{1} },如果payement_type
设置为new,它将使用新的子表单,在其他情况下,它将获取和旧的payement并将其添加到子表单,禁用为true。
我已经有嵌套表单的形式和部分,我已经像这样使用了link_to_add_association:
payement_type
这里是我的3个问题:
1)如何将字段内的值传递给嵌套表单partial?
2)如何使用传递给partial的局部文件来获取数据库中的旧付款并用它填充子表单?
3)有更好的方法来实现我想做的事情吗?