1

我做了一个小项目参考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'`

谁来帮帮我?

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

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
4

1 回答 1

0

尝试从 Answer 模型中删除 :as => :author,并在 has_reputation :avg_rating 的初始化中设置 :of => :user。

于 2014-01-10T18:05:26.983 回答