Skip to content

Instantly share code, notes, and snippets.

@andreas-it-dev
Last active February 2, 2016 16:48
Show Gist options
  • Save andreas-it-dev/a55eac83f054c98b204e to your computer and use it in GitHub Desktop.
Save andreas-it-dev/a55eac83f054c98b204e to your computer and use it in GitHub Desktop.
NoMethodError in StocksController#show
undefined method `times' for #<String:0x007f9bef44ed40>
Extracted source (around line #19):
17
18
19
20
21
22
data_table.new_column('number', 'Price')
# Add Rows and Values
data_table.add_rows(@stock.daily_prices.pluck(:date, :close).to_json)
option = { width: 400, height: 240, title: 'Company Performance' }
@chart = GoogleVisualr::Interactive::AreaChart.new(data_table, option)
Rails.root: /home/andreas/railsdev/alphatrade
Application Trace | Framework Trace | Full Trace
app/controllers/stocks_controller.rb:19:in `show'
Request
Parameters:
{"id"=>"1"}
Toggle session dump
Toggle env dump
Response
Headers:
None
Processing by StocksController#show as HTML
Parameters: {"id"=>"1"}
Stock Load (0.1ms) SELECT "stocks".* FROM "stocks" WHERE "stocks"."id" = $1 LIMIT 1 [["id", 1]]
(8.1ms) SELECT "daily_prices"."date", "daily_prices"."close" FROM "daily_prices" WHERE "daily_prices"."dailydata_id" = $1 AND "daily_prices"."dailydata_type" = $2 [["dailydata_id", 1], ["dailydata_type", "Stock"]]
Completed 500 Internal Server Error in 221ms (ActiveRecord: 8.2ms)
NoMethodError (undefined method `times' for #<String:0x007f9bef44ed40>):
app/controllers/stocks_controller.rb:19:in `show'
Rendered /usr/local/lib64/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (4.2ms)
Rendered /usr/local/lib64/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.8ms)
Rendered /usr/local/lib64/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms)
Rendered /usr/local/lib64/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (19.6ms)
class StocksController < ApplicationController
before_action :set_stock, except: [:index, :new, :create]
def index
@stocks = Stock.all
respond_to do |format|
format.html
format.json { render json: StocksDatatable.new(view_context) }
end
end
def show
data_table = GoogleVisualr::DataTable.new
# Add Column Headers
data_table.new_column('string', 'Date' )
data_table.new_column('number', 'Price')
# Add Rows and Values
data_table.add_rows(@stock.daily_prices.pluck(:date, :close).to_json)
option = { width: 400, height: 240, title: 'Company Performance' }
@chart = GoogleVisualr::Interactive::AreaChart.new(data_table, option)
end
def new
@stock = Stock.new
end
def create
@stock = Stock.new(stock_params)
if @stock.save
redirect_to stocks_url
else
render :new
end
end
def edit
end
def update
if @stock.update(stock_params)
redirect_to @stock, notice: "Security successfully updated!"
else
render :edit
end
end
def destroy
@stock.destroy
redirect_to stocks_url, notice: "Security successfully deleted!"
end
private
def stock_params
params.require(:stock).
permit(:name, :symbol, :profile, :address, :phone, :email, :website)
end
def set_stock
@stock = Stock.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment