Counting words for visual details

I think you'd be helped more by having a database schema that matches what you want to do better. Something like this sketch:

Detail: (id, name, position) acts_as_list, if you need the words to come up in order

DescriptiveWord: (id, name, position) [similar to above]

SurveyResponse: (id, user_id, detail_id, descriptive_word_id) (note that your app logic will need to constrain the user to 3 words)

All the usual associations can be set up based on this, and things like @detail.survey_reponses.count(:group => 'descriptive_word_id') [counts responses to a particular @detail and returns a hash of word_id => count; you can get the names with some clever :join usage] will work out of the box.

--Matt Jones