Class: Iro::StocksController
- Inherits:
-
ApplicationController
- Object
- Wco::ApplicationController
- ApplicationController
- Iro::StocksController
- Defined in:
- app/controllers/iro/stocks_controller.rb
Overview
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #sync ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/iro/stocks_controller.rb', line 8 def create @stock = Iro::Stock.new(stock_params) :create, @stock if @stock.save flash_notice @stock else flash_alert @stock end redirect_to action: :index end |
#destroy ⇒ Object
20 21 22 23 |
# File 'app/controllers/iro/stocks_controller.rb', line 20 def destroy @stock.destroy redirect_to stocks_url, notice: 'Stock was successfully destroyed.' end |
#edit ⇒ Object
25 26 27 |
# File 'app/controllers/iro/stocks_controller.rb', line 25 def edit :edit, @stock end |
#index ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/iro/stocks_controller.rb', line 29 def index @stocks = Iro::Stock.all :index, Iro::Stock respond_to do |format| format.html format.json do render layout: false end end end |
#new ⇒ Object
41 42 43 44 |
# File 'app/controllers/iro/stocks_controller.rb', line 41 def new @stock = Iro::Stock.new :new, @stock end |
#show ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/iro/stocks_controller.rb', line 57 def show :show, @stock @priceitems = ::Iro::Priceitem.where({ ticker: @stock.ticker, }) @datapoints = Iro::Datapoint.where({ symbol: @stock.ticker, }).order_by({ date: :desc }).limit(100) respond_to do |format| format.html format.json do render layout: false end end end |
#sync ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/iro/stocks_controller.rb', line 46 def sync :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 |
#update ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/iro/stocks_controller.rb', line 75 def update @stock = Iro::Stock.find params[:id] :update, @stock if @stock.update(stock_params) flash_notice @stock else flash_alert @stock end redirect_to request.referrer end |