1
我做了一個小項目引用Quick Start
,但是當我訪問的評價值出現了錯誤ActiveRecord的聲譽系統不工作
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 &中的用戶業力用戶業力是提問技能和應答技能總和的網站。提問技巧是用戶問題的投票總數,而回答技巧是用戶答案的平均評分的總和。這可以被定義如下:
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
您應該發佈更多的代碼。 – jcm