Skip to content

Instantly share code, notes, and snippets.

@benphelps
Created October 23, 2012 05:12
Show Gist options
  • Save benphelps/a8e5110c432e44a76a0b to your computer and use it in GitHub Desktop.
Save benphelps/a8e5110c432e44a76a0b to your computer and use it in GitHub Desktop.
if stock = @account.stocks.find_by_name(stock.pretty_symbol)
if stock.price == price.cents
stock.amount += amount
else
@account.stocks << Stock.new(name: stock.pretty_symbol, price: price.cents, amount: amount)
end
else
@account.stocks << Stock.new(name: stock.pretty_symbol, price: price.cents, amount: amount)
end
@account.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment