Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uninitialized constant CustomerBill::CustomerBillLineItem

I created an association between customer_bill and customer_bill_line_item as follows:

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

When I enter a form in create mode, I get the following error:

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%>

The full stack trace is given in the comment.

Is there an association that must be made in customer_bills_controller like@customer_bill.customer_bill_line_items??

Guidance required. Thanks in advance.

like image 895
bharath Avatar asked Jan 14 '23 07:01

bharath


1 Answers

I quickly threw an example app together to prove what you were doing was right, you can check it out here: https://github.com/Bram--/customer_bill which works fine. Just make sure before you spin it up you have a 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

What versions are you using, is there anything else we're not seeing in the above code?

Hope the example helps, otherwise drop me a line.

like image 64
Novae Avatar answered Jan 16 '23 21:01

Novae