· 1 min read

Screencast: Diagramme in Rails Applikationen verwenden

Download:

Download(29.1 MB, 16:12) Alternativer Download für iPod & Apple TV(27.4 MB, 16:12)

Resourcen:

Quellcode:

[html] <%= javascript_include_tag “jquery-1.4.2.min”, “rails”, “highcharts” %>

\[/html\]

[ruby] # rails c Order.group(“date(purchased_at)“).select(“purchased_at, sum(total_price) as total_price”).first.total_price.to_f Order.group(“date(purchased_at)“).select(“purchased_at, sum(total_price) as total_price”).first.purchased_at.to_date

# models/order.rb scope :shipping, where(:shipping => true) scope :download, where(:shipping => false)

def self.total_on(date) where(“date(purchased_at) = ?”, date).sum(:total_price) end

# orders_helper.rb def orders_chart_series(orders, start_time) orders_by_day = orders.where(:purchased_at => start_time.beginning_of_day..Time.zone.now.end_of_day). group(“date(purchased_at)”). select(“purchased_at, sum(total_price) as total_price”) (start_time.to_date..Date.today).map do |date| order = orders_by_day.detect { |order| order.purchased_at.to_date == date } order && order.total_price.to_f || 0 end.inspect end [/ruby]

Back to Blog