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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With