0

I have a code that once i create the order, it will automatically fill up information for the order items (because every order has many items) but i have the error uninitialized constant Order::OrderItem. How do i solve this?

Model

class Order < ActiveRecord::Base
  # attr_accessible :title, :body
  attr_accessible :amount, :currency


  has_many :order_items
end

class OrderItems < ActiveRecord::Base
  attr_accessible :items, :order_id, :quantity

  belongs_to :order
end

Controller

 def checkout
    @order = Order.new # Create new order
    @order.total = @shopping_cart.total
    @order.sub_total = @shopping_cart.subtotal
    @order.sales_tax = @shopping_cart.taxes

    @shopping_cart.shopping_cart_items.each do |cart_item|
       @orderitems = @order.order_items.build(items: cart_item.item.name, quantity: cart_item.quantity)
    end
 end
muhammadn
  • 330
  • 3
  • 18

1 Answers1

1

uninitialized constant Order::OrderItem

The problem is with this line

class OrderItems < ActiveRecord::Base

Model class names supposed to be singular.Change OrderItems to OrderItem.And also don't forget to change the model file name as well.

Pavan
  • 33,316
  • 7
  • 50
  • 76