ruby-on-rails – 未初始化的常量CustomerBill :: CustomerBillL
发布时间:2020-12-17 03:47:27 所属栏目:百科 来源:网络整理
导读:我在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_attri
我在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: 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 您使用的是什么版本,我们在上面的代码中没有看到任何其他内容? 希望这个例子有所帮助,否则请给我留言. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |