I need to count how many users were created for every day last week. I created something like this:
users = User.where(created_at: (Time.now - 7.day)..Time.now)
users.group_by{|p| p.created_at.at_beginning_of_day}.each do |day, array|
puts "on #{day} #{array.size}"
end
I want to output to be:
on Sun 29
on Mon 34
etc.
but instead of that I get this:
{Sun, 25 Aug 2013 00:00:00 CEST +02:00=>[#<User id: 10, email: "jssdc@ssds.cz", encrypted_password: "$2a$10$QWz7p86JAURxvWJj8GZFm.o2a589y7T4htcOJyUqe4aK...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2013-08-25 12:30:05", updated_at: "2013-08-25 12:30:40", authentication_token: "ytMoqBwRHVZseN7bbsvU", confirmation_token: "fuWEN7DGhC6XpRqtSpWR", confirmed_at: nil, confirmation_sent_at: "2013-08-25 12:30:05", unconfirmed_email: nil>], Tue, 27 Aug 2013 00:00:00 CEST +02:00=>[#<User id: 11, email: "bz@sefdsa.cz", encrypted_password: "$2a$10$4ZZq58B.az9vZ1TFaNVkVeN7PyLRogKEilpV8VvXFY1u...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2013-08-27 21:44:06", updated_at: "2013-08-27 21:44:06", authentication_token: "A1MPhxUQLsPDNSo25xUK", confirmation_token: "sipxKTmuNNvnp4RePsYd", confirmed_at: nil, confirmation_sent_at: "2013-08-27 21:44:06", unconfirmed_email: nil>], Wed, 28 Aug 2013 00:00:00 CEST +02:00=>[#<User id: 12, email: "fdsafdas@sfdsa.cz", encrypted_password: "$2a$10$y/RGxp5dpwq.jpV2d9HTAOLgLFjqgtJnS6IWpFyFwxLj...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2013-08-27 23:00:43", updated_at: "2013-08-27 23:00:43", authentication_token: "UE9ty2K5EoRgm4oveMhf", confirmation_token: "a7186dyyyVNMyBpTpJ6k", confirmed_at: nil, confirmation_sent_at: "2013-08-27 23:00:43", unconfirmed_email: nil>, #<User id: 13, email: "madafaka@lol.cz", encrypted_password: "$2a$10$2yDV5KNs3JMpP.OJ/f6rQOgu6P6DFS/Xoc33eYtlAJ6z...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2013-08-27 23:58:51", updated_at: "2013-08-27 23:58:51", authentication_token: "fieiR4ZJ9y9PWux82CLq", confirmation_token: "9ujvWvbvnubyZWisM4sy", confirmed_at: nil, confirmation_sent_at: "2013-08-27 23:58:51", unconfirmed_email: nil>]}
How can I output the created users every day for last week in the desired format?