Skip to content

Instantly share code, notes, and snippets.

@Znow
Created December 28, 2011 09:46
Show Gist options
  • Save Znow/1527365 to your computer and use it in GitHub Desktop.
Save Znow/1527365 to your computer and use it in GitHub Desktop.
def create
@stock = Stock.new(params[:stock])
@is = InvestorStock.new(params[:investor_id])
respond_to do |format|
if @stock.save && @is.save
format.html { redirect_to admin_stock_url(@stock), notice: 'Stock was successfully created.' }
format.json { render json: @stock, status: :created, location: @stock }
else
format.html { render action: "new" }
format.json { render json: @stock.errors, status: :unprocessable_entity }
end
end
end
@pacso
Copy link

pacso commented Dec 28, 2011

def create
    @stock = Stock.new(params[:stock])
    @is = InvestorStock.new(params[:investor_id])

    respond_to do |format|
      if @stock.save
        @is.stock_id = @stock.id
        @is.save
        format.html { redirect_to admin_stock_url(@stock), notice: 'Stock was successfully created.' }
        format.json { render json: @stock, status: :created, location: @stock }
      else
        format.html { render action: "new" }
        format.json { render json: @stock.errors, status: :unprocessable_entity }
      end
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment