【发布时间】:2015-03-28 01:21:07
【问题描述】:
我创建了一个迷你投票游戏,我想在饼图中显示用户的投票。我使用 Chartkick 来做到这一点,我的代码在这里:
<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>
我希望相应地显示option.title 和option.votes。这是vote_option.rb 模型:
class VoteOption < ActiveRecord::Base
belongs_to :poll
has_many :votes, dependent: :destroy
has_many :users, through: :votes
validates :title, presence: true
end
这是我得到的错误:
ActionView::Template::Error (undefined method `group' for #<Poll:0x007f0a1c2610b0>)
对这个问题有什么想法吗?
【问题讨论】:
-
也许你的意思是
@poll.poll_options.group(:title).count('votes')? -
@DylanMarkow 我的项目中没有
poll_options方法