Sha256: fde0f2b6dcf243431ef00dabad466d40c8c1d4dce3e999f676510df4a38162cb

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 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
  end

  def index
    @stocks = Iro::Stock.all
    authorize! :index, Iro::Stock
  end

  def new
    @stock = Iro::Stock.new
    authorize! :new, @stock
  end

  def refresh
    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 'ok'
    redirect_to request.referrer
  end

  def show
  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

3 entries across 3 versions & 1 rubygems

Version Path
iron_warbler-2.0.7.25 app/controllers/iro/stocks_controller.rb
iron_warbler-2.0.7.24 app/controllers/iro/stocks_controller.rb
iron_warbler-2.0.7.23 app/controllers/iro/stocks_controller.rb