I've create a mini poll game and I want to show the user's votes in pie chart. I used Chartkick to do that, my code here:
<div class="form-group">
<%= content_tag(:label) do %>
<% unless current_user.voted_for?(@poll) %>
<%= radio_button_tag 'vote_option[id]', option.id %>
<% end %>
<%= option.title %>
<% end %>
<%= visualize_votes_for option %>
<%= pie_chart @poll.group(:title).count('votes') %>
</div>
I expected to display option.title
and option.votes
correspondingly. Here is a vote_option.rb
model:
class VoteOption < ActiveRecord::Base
belongs_to :poll
has_many :votes, dependent: :destroy
has_many :users, through: :votes
validates :title, presence: true
end
And here is the error that I got:
ActionView::Template::Error (undefined method `group' for #<Poll:0x007f0a1c2610b0>)
Any idea for this issue?