编辑说明:这是关于Railscast#364中涉及的activerecord-reputation-system gem的问题
我有一个应用程序,其中Vip
和类的用户可以为他们最喜欢的对象Peon
投票。Idea
我能够成功地收集vip_votes
和peon_votes
。我怎样才能将两种投票类型聚合成total_votes
?我有下面的代码,但 total_votes 没有按预期累积。
想法.rb
has_reputation :vip_votes,
:source => :vip,
:aggregated_by => :sum
has_reputation :peon_votes,
:source => :peon,
:aggregated_by => :sum
has_reputation :total_votes,
:source => [{ :reputation => :vip_votes },
{ :reputation => :peon_votes, :weight => 0.8 }],
:aggregated_by => :sum
想法控制器.rb
def vip_vote
@design = Design.find(params[:id])
@design.add_evaluation(:vip_votes, 1, current_vip)
end
def peon_vote
@design = Design.find(params[:id])
@design.add_evaluation(:peon_votes, 1, current_peon)
end
路线.rb
resources :ideas do
member { post :vip_vote }
member { post :peon_vote }
end
感谢您的反馈意见!