All pastes #547169 Raw Edit

Someone

public text v1 · immutable
·published 2007-06-07 09:11 UTC
rendered paste body
  def create
    @product = Product.new(params[:product])
    
    if params[:category] == "" #hoping this would mean if the textfield is blank, then use the selection box, else, create a new category.
      @product.category = (params[:category_id])
    else
      @category = Category.create(params[:category])
      @product.category = @category
    end
    
    if @product.save
      flash[:notice] = 'Product was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def update
    @product = Product.find(params[:id])
        
    if params[:category] == "" #hoping this would mean if the textfield is blank, then use the selection box, else, create a new category.
      @product.category = (params[:category_id])
    else
      @category = Category.create(params[:category])
      @product.category = @category
    end
        
    if @product.update_attributes(params[:product])
      flash[:notice] = 'Product was successfully updated.'
      redirect_to :action => 'show', :id => @product
    else
      render :action => 'edit'
    end
  end