Twitter信誉系统Gem无法批量分配受保护的属性

时间:2015-09-11 05:46:00

标签: ruby-on-rails ruby ruby-on-rails-3 rubygems

我关注http://railscasts.com/episodes/364-active-record-reputation-system

在我的用户模型上我有:

has_many :evaluations, class_name: "RSEvaluation", as: :source

has_reputation :votes, source: {reputation: :votes, of: :articles}, aggregated_by: :sum

def voted_for?(article)
  evaluations.where(target_type: article.class, target_id: article.id).present?
end

我有文章模型:

has_reputation :votes, source: :user, aggregated_by: :sum

文章管理员:

def vote
  value = params[:type] == "up" ? 1 : -1
  @article = article.find(params[:id])
  @article.add_or_update_evaluation(:votes, value, current_user)
  redirect_to :back
end

但是当我去投票时:

  

无法批量分配受保护的属性:reputation_name,value,   source_id,source_type,target_id,target_type

任何人对此宝石都有同样的问题吗?

1 个答案:

答案 0 :(得分:2)

质量分配错误表明您正在使用Rails 3中的信誉gem。您需要将gem降级到版本2.

在Gemfile中,指定版本2.

# Gemfile
gem 'activerecord-reputation-system', '~> 2.0', require: 'reputation_system'

然后更新你的捆绑。

bundle update activerecord-reputation-system