I have my model class
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
In my controller I am doing create Location object in two ways
Location.new(result) #works fine
@post.location.new #get error
Why in second case its looking for constructor with 2 arguments. I also added constructor with two arguments but it didnt work.
I get error
wrong number of arguments (2 for 1)
Edit :
How do i make @post.location.new work ?
You’re overwriting the constructor for
Locationto take exactly one argument, so now you’ll have to provide it with each call ofnew. Your best bet is probably not to do that, or at least to provide a default, something like this:To build an empty association, you can then use
or