activerecord-reputation-system无法正常工作

时间:2013-10-07 09:23:19

标签: ruby-on-rails

我做了一个小项目参考Quick Start,但当我访问信誉值时发生错误

answer.reputation_for :avg_rating

NoMethodError: undefined method `to_sym' for nil:NilClass
from /Users/Juo/.rvm/gems/ruby-2.0.0-p195/bundler/gems/activerecord-reputation-system-01197ad78cac/lib/reputation_system/models/reputation.rb:189:in `get_target_type_for_sti'
from /Users/Juo/.rvm/gems/ruby-2.0.0-p195/bundler/gems/activerecord-reputation-system-01197ad78cac/lib/reputation_system/models/reputation.rb:198:in `set_target_type_for_sti'
from /Users/Juo/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:377:in `_run__3152603553061474011__validation__callbacks'`

有人帮助我吗?

  

假设我们想在Q& A网站中跟踪用户业力,其中用户业力是提问技巧和回答技巧的总和。提问技巧是用户问题的总票数,答案技能是用户答案的​​平均评分之和。这可以定义如下:

class User < ActiveRecord::Base
  has_many :answers
  has_many :questions

  has_reputation :karma,
      :source => [
          { :reputation => :questioning_skill, :weight => 0.8 },
          { :reputation => :answering_skill }]

  has_reputation :questioning_skill,
      :source => { :reputation => :votes, :of => :questions }

  has_reputation :answering_skill,
      :source => { :reputation => :avg_rating, :of => :answers }
end

class Answer < ActiveRecord::Base
  belongs_to :user, :as => :author

  has_reputation :avg_rating,
      :source => :user,
      :aggregated_by => :average,
      :source_of => [{ :reputation => :answering_skill, :of => :author }]
end


class Question < ActiveRecord::Base
  belongs_to :user

  has_reputation :votes,
      :source => :user
end

1 个答案:

答案 0 :(得分:0)

尝试删除:as =&gt; :来自答案模型的作者,并设置:of =&gt; :用户初始化has_reputation:avg_rating。