Sha256: d769c2ea9e4aeac3340f643077f5ef6375cb5629741f2315773955ad07def103
Contents?: true
Size: 1.69 KB
Versions: 10
Compression:
Stored size: 1.69 KB
Contents
class Iro::StocksController < Iro::ApplicationController before_action :set_stock, only: [:show, :edit, :update, :destroy] def create @stock = Iro::Stock.new(stock_params) authorize! :create, @stock if @stock.save flash_notice @stock else flash_alert @stock end redirect_to action: :index end def destroy @stock.destroy redirect_to stocks_url, notice: 'Stock was successfully destroyed.' end def edit authorize! :edit, @stock end def index @stocks = Iro::Stock.all authorize! :index, Iro::Stock respond_to do |format| format.html format.json do render layout: false end end end def new @stock = Iro::Stock.new authorize! :new, @stock end def sync authorize! :refresh, Iro::Stock tickers = Iro::Stock.all.map { |s| s.ticker }.join(',') outs = Tda::Stock.get_quotes tickers outs.map do |out| Iro::Stock.where( ticker: out[:symbol] ).update( last: out[:last] ) end flash_notice 'refreshed stocks' redirect_to request.referrer end def show authorize! :show, @stock @priceitems = ::Iro::Priceitem.where({ ticker: @stock.ticker, }) respond_to do |format| format.html format.json do render layout: false end end end def update @stock = Iro::Stock.find params[:id] authorize! :update, @stock if @stock.update(stock_params) flash_notice @stock else flash_alert @stock end redirect_to request.referrer end ## ## private ## private def set_stock @stock = Iro::Stock.find(params[:id]) end def stock_params params.require(:stock).permit! end end
Version data entries
10 entries across 10 versions & 1 rubygems