【发布时间】:2015-09-08 01:17:11
【问题描述】:
我有三个模型,auto、perfil 和 user。每个用户都有自己的个人资料。我需要当您发布新汽车时,如果数据不同或及时更改,您可以更新您的个人资料用户。但不像用来更新action create中的action。我使用嵌套属性。
def create
current_user.perfil||= current_user.build_perfil
@perfil = current_user.perfil
@perfil.update_attributes(auto_params)
@auto = @current_user.autos.new(auto_params)
respond_to do |format|
if @auto.save
format.html { redirect_to @auto, notice: 'Auto was successfully created.' }
format.json { render :show, status: :created, location: @auto }
else
format.html { render :new }
format.json { render json: @auto.errors, status: :unprocessable_entity }
end
end
【问题讨论】:
-
您好,您遇到的具体问题是什么?你已经尝试过什么?
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 nested-forms nested-attributes