I'm currently using the nested_forms gem and I'm trying to be able to add multiple landlords to a property.
At the moment the associations are quite deep: Property -> Landlord -> Contact_Detail -> Address
In my Property controller I'm building the associations and the initial form is displayed correctly. However, after using the add fields button, there are no fields. I know it is something to do with the object not getting built, but I can't understand why.
Here's my Property model:
belongs_to :address
belongs_to :estate_agent
belongs_to :property_style
has_and_belongs_to_many :landlord
has_and_belongs_to_many :tenancy_agreement
attr_accessible :landlord_attributes, :address_attributes, :estate_agent_attributes,
:property_style_attributes, :sector, :reference , :occupied, :available_date, :property_style_attributes,...
accepts_nested_attributes_for :landlord, :address, :estate_agent, :property_style, :tenancy_agreement
And here's the new function in the Property controller:
def new
@property = Property.new
@property.build_address
@property.landlord.build.build_contact_detail.build_address
@property.estate_agent_id = current_user.estate_agent_id
respond_to do |format|
format.html # new.html.erb
format.json { render json: @property }
end
end
I've had quite a few attempts at this, but can't see where I'm going wrong, is it a problem with the nested_form gem not supporting this many levels of association or the type of association?
Thanks!