我有我的模型类参数红宝石错误 - 错误的参数数目
class Location < ActiveRecord::Base
belongs_to :post
attr_accessor :address, :category,:name,:postcode,:tel
def initialize(result)
@address = result["address"]
@category = result["category"]
end
end
在我的控制,我在做两个方面
Location.new(result) #works fine
@post.location.new #get error
创建Location对象为什么在第二种情况下其寻找的构造有2个参数。我也添加了两个参数的构造函数,但它没有奏效。
我得到错误
wrong number of arguments (2 for 1)
编辑: 如何使@ post.location.new工作?
它正在寻找一个参数,而不是两个。你只给了一个,然后两个。 “x for y”的意思是“实际上有x是预期的y”。 – sawa
@ post.location.new没有任何参数..我只想要一个空对象。 – harshit
当你不提供参数时,你想要什么值? – sawa