My Models:
class House < ActiveRecord::Base
has_one :house_type
accepts_nested_attributes_for :house_type
end
class HouseType < ActiveRecord::Base
belongs_to :house
end
My houses_controller
def update
house = House.find(params[:id])
if house.update!(house_type_params)
render :json => trip
end
end
private
def house_type_params
params.permit(:attr1, :attr2, house_type_attributes: [:attrA, :attrB])
end
That way it only updates houses' attributes, not house_types'. Don't know what's happening. Help, please!