# Histogram from model-data?

**URL:** <https://www.ruby-forum.com/t/histogram-from-model-data/127524>\
**Category:** Rails\
**Created:** [January 30, 2008, 1:44am UTC](https://www.ruby-forum.com/t/histogram-from-model-data/127524 "2008-01-30T01:44:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [January 30, 2008, 1:44am UTC](https://www.ruby-forum.com/t/histogram-from-model-data/127524/1 "2008-01-30T01:44:29Z")

</div>

I’d like to display some kind of histogram from user-data, but i don’t  
really know the approach to do so. I have a model Vote, they belong to  
a User (user has\_many votes), and each User has a Profile, and in  
there i store things like age, location, etc. (user.profile.age or  
vote.user.profile.age)

I now have a certain collection of votes from which i want a  
histogram, and what i would like to have is for example for the ages a  
result like: 0-20 =\> 15 votes, 21-50 =\> 10 votes, and 50+ =\> 2 votes  
(the collection would have 27 votes)

how do i set this up?

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [January 30, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/histogram-from-model-data/127524/2 "2008-01-30T16:10:19Z")

</div>

The basic thing here that i don’t understand is how to use ‘find’ in  
such a way that it only returns the votes for which the owner’s  
profile gender for example equals ‘m’. I think i have to use :include,  
but can’t really figure out the syntax to do so.
