0

我有一个控制器产品:

def update
@product = Product.find(params[:id])

respond_to do |format|
  if @product.update_attributes(params[:product])
     if @product.brand == nil 
        format.html { redirect_to :controller => 'compositions', :action => 'edit', :id =>  @product } 
        format.json { head :no_content }
      else
        format.html { redirect_to @product, notice: 'Product was successfully updated.' }
        format.json { head :no_content }
      end
  else
    format.html { render action: "edit" }
    format.json { render json: @product.errors, status: :unprocessable_entity }
  end
end

控制器产品调用 Controller Compositions、action edit 和 params :id => @product:

def edit
   @composition = Composition.where("productFather_id=?" , @product)
end

def update
   @composition = Composition.where("productFather_id=?" , @product)

respond_to do |format|
  if @composition.update_attributes(params[:composition])
    format.html { redirect_to "/compositions/new", notice: 'Composition was successfully updated.' }
    format.json { head :no_content }
  else
    format.html { render action: "edit" }
    format.json { render json: @composition.errors, status: :unprocessable_entity }
  end
end

我在视图中搜索产品的编辑组合

请想法谢谢

4

0 回答 0