我卡 -帮助轨belongs_to的
我建立在轨会计应用程序,并有一个模型,其中一个客户将有多个发票以及多种支付(有关这些发票)
下面就让我们来看看一个简单的模型:
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
我有一个嵌套形式,我想展示客户的属性,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>
我是否在我的字段中缺少某些内容显示发票引用数据?我的模型对于轨道来说太复杂了吗?
这是轨道3?你需要在你的f.fields中有一个=因为我认为它显示 – corroded 2011-03-15 05:49:37
谢谢 - 将做 – 2011-03-15 14:00:03