I have the following inside a new
method of an orders_controller
@order = Order.new
Rails gives me the following error:
wrong number of arguments (0 for 1)
app/models/order.rb:2:in `<class:Order>'
app/models/order.rb:1:in `<top (required)>'
app/controllers/orders_controller.rb:33:in `new'
I am using Rails 3.0.5
Thanks!
Edit: order.rb can be found below
class Order < ActiveRecord::Base
has_many :line_items, :dependent => destroy
PAYMENT_TYPES = [ "Check", "Credit card", "Purchase order" ]
validates :name, :address, :email, :pay_type, :presence => true
validates :pay_type, :inclusion => PAYMENT_TYPES
def add_line_items_from_cart(cart)
cart.line_items.each do |item|
item.cart_id = nil
line_items << item
end
end
end
You have a typo in your code. You missed a :
in the :destroy
Change :dependent => destroy
in line 2 to :dependent => :destroy
. It should work.
The first declaration in order.rb
should read:
has_many :line_items, :dependent => :destroy
精彩评论