At 6:30 in this RailsCast it mentions real data is going to be used instead of arbitrary data.
The line in the /app/views/orders/index.html.erb file
data: [1, 2, 5, 7, 3]
is replaced with
data: <%= (3.weeks.ago.to_date..Date.today).map { |date| Order.total_on(date).to_f}.inspect %> }]
At 7:30 he then create a class method in the order model.
/app/models/order.rb
class Order < ActiveRecord::Base
def self.total_on(date)
where("date(purchased_at) = ?",date).sum(:total_price)
end
end
I don't understand how this fetches the real data. How is it taken from the database? He refers to the orders table numerous times but I don’t see where where the connection is made.
Thanks for reading.