我的模特:
class House < ActiveRecord::Base
has_one :house_type
accepts_nested_attributes_for :house_type
end
class HouseType < ActiveRecord::Base
belongs_to :house
end
我的house_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
这样它只会更新房屋的属性,而不是更新house_types'。不知道发生了什么。求救!