Reputation: 3031
I'm having trouble getting this to work. I want to use nested attributes in a form, but before I do that I need to be able to build a person (administrator) from event, like so:
@event = Event.new
@event.administrator.build
#=> undefined method 'build' for nil:NilClass
class Event < ActiveRecord::Base
#start_date, end_date, title
has_one :administrator, :class_name => "Person"
has_one :account_manager, :class_name => "Person"
accepts_nested_attributes_for :administrator
end
class Person < ActiveRecord::Base
#fname, lname, bday
belongs_to :event
end
Any help?
Upvotes: 0
Views: 477
Reputation: 886
I think you need to use build_administrator instead...
@event = Event.new
@event.build_administrator
This is because you have a 'has_one' association, therefore there is no association proxy created by default.
Upvotes: 2