Hello, I have 2 models, city and tip. A city an have only one tip. So what i am trying to do is to add my tip properties to the city form and create or update the city with his child the tip. but what i've done so far isn't working... I have this error: undefined method `build' for nil:NilClass
Model City: class City < ActiveRecord::Base attr_accessible :name, :continent, :tip_attribute
has_one :shop belongs_to :city_preferences belongs_to :tip
validates_presence_of :name,:continent def tip_attribute tip end
def tip_attribute=(attribute) tip.build(attribute) end
end
City form view: <% form_for @city do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <p> <%= f.label :continent %><br /> <%= f.text_field :continent %> </p> <p><%= f.label :Tip %></p> <%fields_for "city[tip_attribute]", @city.tip do |t| %> <p>Min <%= t.text_field :min %><br /> <p>Max <%= t.text_field :max %> <%end%> <p><%= f.submit "Submit" %></p> <% end %>
Greg