Ruby-on-rails – How to count the number of records that have a unique value in a particular field in ROR


I have a record set that includes a date field, and want to determine how many unique dates are represented in the record set.

Something like:


but of course, that doesn't seem to work.

Best Solution

This has changed slightly in rails 4 and above :distinct => true is now deprecated. Use:


Or if you want the date and the number: