Suppose I have a model with two fields: a name and a street name .
How to find out the number of different street names * in the controller method?
This will return the total number of different street_names
Model.group(:street_name).all.count
This will return an ordered hash with counting names on each street
Model.group(:street_name).count
why don't you do "count_by_sql" where you would use the query select count(*) from (select distinct(street_name) from <table_name>)
select count(*) from (select distinct(street_name) from <table_name>)
Other things you can do in ruby: <ModelName>.all.group_by(&:street_name).size
<ModelName>.all.group_by(&:street_name).size
Try it!
Model.find(:all,:select => 'DISTINCT street_name').size