默认更新 nested_attributes

Update nested_attributes by default

我尝试更新 iproduction,一个来自生产的嵌套表单,但我在这行出现了参数错误: "wrong number of arguments (0 for 1)"

@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

你能帮我解释一下语法吗?

应该是@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