Class: Iro::Api::StocksController
- Inherits:
-
Iro::ApiController
- Object
- Iro::ApiController
- Iro::Api::StocksController
- Defined in:
- app/controllers/iro/api/stocks_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 52 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
75 76 77 78 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 75 def destroy @stock.destroy redirect_to stocks_url, notice: 'Stock was successfully destroyed.' end |
#edit ⇒ Object
49 50 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 49 def edit end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 5 def index @stocks = Iro::Stock.active :index, Iro::Stock respond_to do |format| format.html format.json end end |
#new ⇒ Object
44 45 46 47 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 44 def new @stock = Iro::Stock.new :new, @stock end |
#show ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 15 def show :show, @stock end_on = Time.now.to_date.in_time_zone('UTC') begin_on = ( Time.now - 1.year ).to_date.in_time_zone('UTC') begin_on = params[:begin_on].to_date.in_time_zone('UTC') if params[:begin_on] end_on = params[:end_on].to_date.in_time_zone('UTC') if params[:end_on] case params[:period] when '1-mo' begin_on = ( Time.now - 30.days ).to_date.in_time_zone('UTC') # end_on = Time.now.to_date.in_time_zone('UTC') when '3-mo' begin_on = ( Time.now - 90.days ).to_date.in_time_zone('UTC') # end_on = Time.now.to_date.in_time_zone('UTC') when '1-yr' begin_on = ( Time.now - 1.year ).to_date.in_time_zone('UTC') # end_on = Time.now.to_date.in_time_zone('UTC') when '5-yr' begin_on = ( Time.now - 5.years ).to_date.in_time_zone('UTC') end @datapoints = Iro::Datapoint.where({ :quote_at.gte => begin_on, :quote_at.lte => end_on, symbol: params[:ticker], }).order_by({ quote_at: :asc }) end |