默认情况下更新nested_attributes [英] Update nested_attributes by default

查看:72
本文介绍了默认情况下更新nested_attributes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试更新iproduction,这是生产中的嵌套表格,并且此行出现params错误: 参数数量错误(0表示1)"

I try to update iproduction, a nested form from production and I have an error of params with this line : "wrong number of arguments (0 for 1)"

@ production.update.iproductions_attributes(cow_id:@cow)

@production.update.iproductions_attributes(cow_id: @cow)

我的制作动作制作:

def create
    @production = @ranch.productions.create(production_params)
    @production.update(date: Date.today)
    @cows = @ranch.cows
    @cow = Cow.find_by(id: params[:id])
    @production.update.iproductions_attributes(cow_id: @cow)
    respond_to do |format|
      if @production.save
        format.html { redirect_to ranch_production_path(@production.ranch_id, @production), notice: 'Production was successfully created.' }
        format.json { render :show, status: :created, location: @production }
      else
        format.html { render :new }
        format.json { render json: @production.errors, status: :unprocessable_entity }
      end
    end
  end

您能帮我介绍一下语法吗?

Can you help me about the syntax ?

推荐答案

应为@production.iproductions.update_attributes(cow_id: @cow)

   def create
        @production = @ranch.productions.create(production_params)
        @production.update(date: Date.today)
        @cows = @ranch.cows
        @cow = Cow.find_by(id: params[:id])
        @production.iproductions.update_attributes(cow_id: @cow)
        respond_to do |format|
          if @production.save
            format.html { redirect_to ranch_production_path(@production.ranch_id, @production), notice: 'Production was successfully created.' }
            format.json { render :show, status: :created, location: @production }
          else
            format.html { render :new }
            format.json { render json: @production.errors, status: :unprocessable_entity }
          end
        end
      end

这篇关于默认情况下更新nested_attributes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆