开发者

Rails new - wrong number of arguments (0 for 1) [closed]

开发者 https://www.devze.com 2023-04-01 02:56 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that开发者_运维百科 is not g
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that开发者_运维百科 is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消