I want to get all the users count based upon the created at
User.group("Date(created_at)").count
It will give me a output like
{Wed, 03 Aug 2011=>25, Thu, 04 Aug 2011=>22, 06 Aug 2011=>4, Sun, 07 Aug 2011=>6, Mon, 08 Aug 2011=>5}
I want to have an array something like:-
[25,22,0,4,5] // zero is for the dates when no record is there for that date.
@foo = User.group(:created_at).countwill give you your users grouped by their created_at date.As you mentioned you’ll get a hash of
{:date => count}‘sYou could then look at
@foo.values(to get your count array)[25,22,0,4,5], or iterate over it likeEDIT I now understand what you were trying to ask.
You could do something like this