I am trying to make this as efficient as possible which is why I was
trying to do the group call.
I was doing it in the Highchart definition which worked however it does
many queries depending on how many initiatives there are.
series: [{
name: "Trainings",
data: [
<% Initiative.all.each do |initiative| %>
['<%= initiative.name %>',<%= Training.where("initiative_id = ?",
initiative.id).count %>],
<% end %>
]
}],
One of the issues is that there may not be any record count for a
particular initiative so I also need to return a zero but still map the
initiative.
The example from the Railscast is like this and is similar to what I
was trying to do however this example was based on a day mapping.
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
I will try the examples you have given me so far to see if I can
accomplish what I need.
I appreciate the fast responses...
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/32344f96740c7f82508998b4844cd314%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment