Skip to content

Instantly share code, notes, and snippets.

@kiote
Last active August 29, 2015 14:06
Show Gist options
  • Save kiote/ac36155a23bcb64d636a to your computer and use it in GitHub Desktop.
Save kiote/ac36155a23bcb64d636a to your computer and use it in GitHub Desktop.
#
# ContsestContorller
# TODO: some ugly logic here, it's better to add it to Survey gem?
#
def show
q = survey.questions.first
@total_answers = Survey::Answer.where(question: q).count
@options_answers = []
q.options.each do |o|
@options_answers << { count: Survey::Answer.where(question: q, option: o).count, text: o.text }
end
end
#
# show.html.erb
#
Total answers: <%= @total_answers %><br/>
<% @options_answers.each do |o| %>
<%= o[:text] %>:<%= o[:count] %><br/>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment