3

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
joshim5
  • 2,292
  • 4
  • 28
  • 40

2 Answers2

14

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.

rubyprince
  • 17,559
  • 11
  • 64
  • 104
  • That's what I just wrote above...no need to respost an answer – joshim5 Sep 01 '11 at 17:39
  • 2
    @joshim5..I posted my answer before u posted...check the time of posting..it is not a repost..infact it is urs which is a repost ;) – rubyprince Sep 01 '11 at 17:42
  • that's incorrect. I posted mine 2 minutes before yours. – joshim5 Sep 01 '11 at 20:48
  • @joshim5..please click the `oldest` tab...you can see my answer first..and you can check the time of posting also by keeping the cursor near the name section in each answer and seeing the tooltip..and if that is not enough, check this [screenshot](http://www.flickr.com/photos/67059624@N02/6105391093/)..you can see my answer was posted 3 minutes before you posted..SO site says so..if u dont believe..it is fine with me ;) – rubyprince Sep 02 '11 at 11:16
2

The first declaration in order.rb should read:

  has_many :line_items, :dependent => :destroy
joshim5
  • 2,292
  • 4
  • 28
  • 40