控制器和视图轨道

时间:2013-06-06 12:13:56

标签: ruby-on-rails edit

我有一个控制器产品:

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

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

请心谅

0 个答案:

没有答案