Ruby on Rails Monday, February 25, 2013

On Monday, February 25, 2013 5:49:56 PM UTC, Ruby-Forum.com User wrote:

def self.users_by_month(start)
    users = where(occurred_at: start.beginning_of_day..Time.zone.now )
    users = users.group("date(occurred_at)")
    users = orders.select("occurred_at, count(name) as user_name")
    users.each_with_object({}) do |user, names|
       names[user.occurred_at.to_date] = user.user_name
    end
  end


I think you're overcomplicating a little - if you do User.where(....).group('date(occurred_at), name').count then you should get back a hash of where the keys are [date,name] pairs and the values are the counts
 
Fred
Thanks in advance,

Ryan

--
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/msg/rubyonrails-talk/-/M7HWOruUhWQJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment