无法更新嵌套属性/ Ruby on Rails

时间:2015-03-03 18:20:55

标签: ruby-on-rails

我的模特:

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'。不知道发生了什么。求救!

0 个答案:

没有答案