acts_as_tree和rails 3.2.3,不兼容?

时间:2012-05-30 05:52:30

标签: ruby-on-rails acts-as-tree

我正在使用Rails 3.2.3和acts_as_tree 1.1.0。我一直在使用acts_as_tree与早期版本的Rails 3(例如3.1.1。)进行一些不同的项目,没有任何问题,但是对于这个版本它根本不起作用。如果是因为3.2.3或我使用的其他东西,我无法确认。

这是我试过的,无济于事: - 在几个不同的控制器上使用acts_as_tree - 仅使用acts_as_tree(没有订单声明) - 运行bundle install和bundle update - 仔细检查parent_id是否存在且是整数

首先,当我尝试这个时,我首先尝试:

undefined method `acts_as_tree'

重新加载页面(并没有做任何其他事情)导致:

undefined method `key?' for nil:NilClass

然后重新启动服务器导致启动失败(应用程序崩溃而不启动),并出现以下错误:

/Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require': /Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:78: odd number list for Hash (SyntaxError)
        foreign_key:   "parent_id",
                    ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:78: syntax error, unexpected ':', expecting '}'
        foreign_key:   "parent_id",
                    ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:78: syntax error, unexpected ',', expecting kEND
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:79: Can't assign to nil
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:80: syntax error, unexpected ':', expecting '='
        counter_cache: nil,
                      ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:80: Can't assign to nil
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:81: syntax error, unexpected ':', expecting '='
        dependent:     :destroy
                  ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:82: syntax error, unexpected '}', expecting kEND
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:86: syntax error, unexpected ':', expecting kEND
      belongs_to :parent, class_name:    name,
                                     ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:87: syntax error, unexpected ':', expecting '='
        foreign_key:   configuration[:foreign_key],
                    ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:88: syntax error, unexpected ':', expecting '='
        counter_cache: configuration[:counter_cache],
                      ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:89: syntax error, unexpected ':', expecting '='
        inverse_of:    :children
                   ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:91: syntax error, unexpected ':', expecting kEND
      has_many :children, class_name:  name,
                                     ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:92: syntax error, unexpected ':', expecting '='
        foreign_key: configuration[:foreign_key],
                    ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:93: syntax error, unexpected ':', expecting '='
        order:       configuration[:order],
              ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:94: syntax error, unexpected ':', expecting '='
        dependent:   configuration[:dependent],
                  ^
/Library/Ruby/Gems/1.8/gems/acts_as_tree-1.1.0/lib/acts_as_tree.rb:95: syntax error, unexpected ':', expecting '='
        inverse_of:  :parent
                   ^
    from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler.rb:119:in `require'
    from /Users/Christoffer/Documents/Webbprojekt/rails/Presenttips/config/application.rb:7
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:53:in `require'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:53
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:50
    from script/rails:6:in `require'
    from script/rails:6

这让我觉得有一个兼容性问题btw Rails 3.2.3和acts_as_tree。我不知道如何验证这一点。

我有哪些选择?我不一定需要使用Rails 3.2.3但是如果我降级到3.1.1。 (我尝试过)我遇到其他似乎更糟糕的问题(“文件设置”似乎不一样)。

那么,我的选择是什么?你也经历过这个吗? acts_as_tree有问题,对吧?

1 个答案:

答案 0 :(得分:3)

看起来从2年前开放

  

2年前打开此问题不适用于Rails 2.3.8 https://github.com/rails/acts_as_tree/issues/1

选项

acts_as_tree_rails3 gem install acts_as_tree_rails3

nested_set https://github.com/skyeagle/nested_set

修改

你是对的,新位置是https://github.com/amerine/acts_as_tree同一作者

带评论

  

如果Rails / ActiveRecord较旧,我们不再支持Ruby 1.8或版本   比3.0。如果您使用的是早于3.0的ActiveRecord版本   请使用0.1.1。

     

继续前进,我们将尽力支持最新版本的   ActiveRecord和Ruby

这就是为什么他们不打扰那些已经解决的问题