首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >行动-声誉-系统不起作用

行动-声誉-系统不起作用
EN

Stack Overflow用户
提问于 2013-10-07 09:23:18
回答 1查看 170关注 0票数 1

我做了一个小的项目引用Quick Start,但是当我访问信誉值时发生了一个错误。

answer.reputation_for :avg_rating

代码语言:javascript
复制
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'`

谁来帮我?

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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2014-01-10 18:05:26

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19221098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档