尝试从Rails 4.0.4升级到4.1.0 gem'actage_as_commentable_with_threading'会导致错误

时间:2014-05-06 06:57:53

标签: ruby-on-rails

尝试将Rails从版本4.0.4升级到4.1.0。注释模型中的此语句会导致运行时错误

评论模型

class Comment < ActiveRecord::Base
  include ActiveModel::ForbiddenAttributesProtection

  # added by me so comments_on_comments sorted appropriately
  default_scope  { order(:updated_at => :desc) }

  # causes error in rails 4.1.0
  acts_as_nested_set :scope => [:commentable_id, :commentable_type]

  validates :body, :presence => true
  validates :user, :presence => true
  ...

的Gemfile

source 'https://rubygems.org'

ruby '2.1.1'
...
gem 'acts_as_commentable_with_threading', '~> 1.2.0'

在开发日志中导致此错误

Unknown key: :order. Valid keys are: :class_name, :class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache
acts_as_nested_set :scope => [:commentable_id, :commentable_type] -- is highlighted

评论&#34; acts_as_nested_set:scope =&gt; [:commentable_id,:commentable_type]&#34;在评论模型中,然后在选择文章时会出现此错误(该文章对文章有评论。

undefined method `children' for #<Comment:0x00000107260040>

2 个答案:

答案 0 :(得分:2)

这看起来像awesome_nested_setacts_as_commentable_with_threading的依赖关系)和Rails 4.1 / ruby​​ 2.1的已知问题。

https://github.com/collectiveidea/awesome_nested_set/issues/253

尝试将您的awesome_nested_set版本更新为〜&gt;建议使用3.0.0.rc.3。

答案 1 :(得分:0)

这可能与awesome_nested_set中已弃用的语法有关。我在使用acts_as_commentable_with_threading gem v.2.1.6:

时在rSpec中出现此错误
DEPRECATION WARNING: The following options in your Comment.has_many :children declaration are deprecated: :order. Please use a scope block instead. For example, the following:

    has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

    has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'
. (called from <class:Comment> at /Users/reconstructions/Desktop/Coding 2013/Rails Apps/sfrc/app/models/comment.rb:2)

导致此错误的行与上面描述的相同,并且作用域语法是陈旧的。

撞到gem "awesome_nested_set", '~> 3.0.0.rc.3'为我工作,所以上面的答案是正确的。如果有人不能或不想碰到那个版本,那么修复此语法错误可能是一个可以开始的地方。

相关问题