I have two models Hotel and Address. Relationships are:
class Hotel
belongs_to :user
has_one :address
accepts_nested_attributes_for :address
You should not build address again
class HotelsController < ApplicationController
def new
@hotel = Hotel.new
end
def create
@hotel = current_user.hotels.build(hotel_params)
# address = @hotel.address.build
# the previous line should not be used
if @hotel.save
flash[:success] = "Hotel created!"
redirect_to @hotel
else
render 'new'
end
end