我在customer_bill和customer_bill_line_item之间创建了一个关联,如下所示:
class CustomerBill < ActiveRecord::Base attr_accessible :customer_bill_line_items_attributes has_many :customer_bill_line_items,:dependent =>:destroy accepts_nested_attributes_for :customer_bill_line_items,:allow_destroy => true end class CustomerBillLineItem < ActiveRecord::Base attr_accessible :customer_bill_id belongs_to :customer_bill,:foreign_key => "customer_bill_id" end
当我在创建模式下输入表单时,我收到以下错误:
uninitialized constant CustomerBill::CustomerBillLineItem Extracted source (around line #66): 63: <%end%> 64: 65: 66: <%= f.fields_for :customer_bill_line_items do |builder| %> 67: <%= render 'customer_bill_line_item_fields',:f => builder %> 68: <%end%>
注释中给出了完整的堆栈跟踪.
是否必须在customer_bills_controller中进行关联,如@customer_bill.customer_bill_line_items?
需要指导.提前致谢.
解决方法
我很快就把一个示例应用程序放在一起证明你做的是对的,你可以在这里查看:
https://github.com/Bram–/customer_bill哪个工作正常.
只需确保在您启动它之前就有一个客户账单& CustomerBillLineItems:
只需确保在您启动它之前就有一个客户账单& CustomerBillLineItems:
c = CustomerBill.create name: 'Name' CustomerBillLineItem.create name: 'Line Item A',price: '1.00',customer_bill_id: c.id CustomerBillLineItem.create name: 'Line Item B',price: '2.00',customer_bill_id: c.id
您使用的是什么版本,我们在上面的代码中没有看到任何其他内容?
希望这个例子有所帮助,否则请给我留言.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。