私は立ち往生しています-
私は会計アプリをレールで構築しており、顧客が複数の請求書と複数の支払い(それらの請求書に関連する)を持つモデルがあります
簡略化されたモデルを簡単に見てみましょう。
class Customer < ActiveRecord::Base
has_many :customer_payments
has_many :invoices
accepts_nested_attributes_for :customer_payments, :allow_destroy => true
end
class CustomerPayment < ActiveRecord::Base
has_many :customer_payment_items
belongs_to :customer
belongs_to :invoice
accepts_nested_attributes_for :customer_payment_items
end
class CustomerPaymentItem < ActiveRecord::Base
belongs_to :invoice, :inverse_of => :customer_payment_items
belongs_to :customer_payment
end
class Invoice < ActiveRecord::Base
has_many :invoice_lines, :dependent => :destroy
has_many :customer_payment_items, :inverse_of => :invoice
belongs_to :customer
accepts_nested_attributes_for :invoice_lines, :allow_destroy => true
end
Customer属性、CustomerPayment属性、CustomerPaymentItem属性を表示するネストされたフォームがあります。これらはすべて正常に機能します。
また、各CustomerPaymentItemの請求書属性を表示したい(各CustomerPaymentItemは単一の請求書に関連している)。CustomerPaymentItem情報を表示するフォームを取得することはできますが、参照を提供するために必要な請求書情報を表示することはできません。ユーザー。-フォームに表示するbelongs_toアソシエーションからデータを取得するのに問題があります。
私は途方に暮れています-belongs_toアソシエーションをトラバースすることはできませんか?参考までに-CustomerPayment.new呼び出し中に請求書データが入力されていることがわかっているログにデータを送信できますが、コントローラーとフォームの間で失われているようです。
そのデータにどのようにアクセスする必要がありますか?これがフォーム情報です-(レンダリングされたいくつかのフォームから)表示されないものは---の間にあります。
<p>
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</p>
<p>
<%= f.label :invoice_id %><br />
<%= f.text_field :invoice_id %>
</p>
<p>
<% f.fields_for :invoice do |builder| %>
--- doesn't show
Invoice Detail
<p>
<%= builder.label :number %><br />
<%= builder.text_field :number %>
</p>
<p>
<%= builder.label :sub_total %><br />
<%= builder.text_field :sub_total %>
</p>
--- doesn't show
<% end %>
</p>
:invoice参照データを表示するためにfields_forに何かが不足していますか?私のモデルは、レールが理解できないほど複雑ですか?