Uninitialized constant CustomerBill :: CustomerBillLineItem

I created a relationship 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 the 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%> 

A full stack estimate is given in the comment.

Is there an association that needs to be made in customer_bills_controller as @customer_bill.customer_bill_line_items ??

Leadership required. Thanks in advance.

+4
source share
3 answers

I quickly added an example application to prove what you are doing, right, you can check it here: https://github.com/Bram--/customer_bill , which works well. Just make sure that before you deploy it, you have a Customer Bill and 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 something else we don’t see in the above code?

Hope this example helps, otherwise write me a line.

+4
source

You asked:

Is there a connection that needs to be made to customer_bills_controller like@customer _bill.customer_bill_line_items ??

In our Novae working layout, it is not (from customer_bills_controller.rb, Novae mock ):

 class CustomerBillsController < ApplicationController def show @customer_bill = CustomerBill.last end def update @customer_bill = CustomerBill.find params[:id] @customer_bill.update_attributes!(params[:customer_bill]) redirect_to @customer_bill, flash: { notice: 'Updated' } end end 

To allow the robot to point out the difference, in its model customer_bill_line_item.rb Novae includes more CustomerBillLineItem attributes in attr_accessible (from the / models / application):

 class CustomerBillLineItem < ActiveRecord::Base attr_accessible :customer_bill_id, :name, :price belongs_to :customer_bill, :foreign_key => "customer_bill_id" end 

I can’t imagine how they lead to your error, but this is what I could find.

+3
source

The error tells you what the problem is. There is no class CustomerBill :: CustomerBillLineItem that can be found.

1: I assume that you are not instantiating customer_bill_line_item in action_bills # new, otherwise you will see the same error.

Please confirm by checking that you are creating instances of customer_bill_line_item on @customer_bill in a new action with something like

 3.times{@customer_bill.customer_bill_line_items.build} 

If you get the same error again, but on the controller assembly line, confirm that it says an error that it cannot find the CustomerBillLineItem class through CustomerBill

I suspect a typo in the file name of the CustomerBillLineItem class. Make sure that your class is located in a file named customer_bill_line_item.rb and is located in your models folder and is not in any other folder. Perhaps the problem is here too.

The bottom line of CustomerBillLineItem is not indicated or correctly placed, and that is why you get this error, which tells you that it cannot find the specified class.

+2
source

All Articles