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

Twitter Reputation System Gem Can't mass-assign protected attributes

我关注了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

但是当我去投票时显示:

Can't mass-assign protected attributes: reputation_name, value, source_id, source_type, target_id, target_type

有人对此有同样的问题吗gem?

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

在您的 Gemfile 中,指定版本 2。

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

然后更新您的捆绑包。

bundle update activerecord-reputation-system