未定义方法中的NoMethodError`scoped'在rails中(使用祖先宝石)

时间:2015-01-05 23:07:19

标签: ruby-on-rails ruby

我正在使用祖先宝石,我首先在控制台中测试我的模型。当我使用时

  root = Message.create(:content => "hello")

它将数据插入数据库,但是当我使用

  child = root.children.create(:content => "hhjjh")

它给出了一个错误。这是日志

  NoMethodError: undefined method `scoped' for #<Class:0x007fa4a61182b0>
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/ancestry-1.2.3/lib/ancestry/instance_methods.rb:136:in `children'
from (irb):2
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/console.rb:90:in `start'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/console.rb:9:in `start'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
from /Users/zeeshandar/chat/bin/rails:8:in `<top (required)>'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/commands/rails.rb:6:in `call'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/command_wrapper.rb:38:in `call'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:183:in `block in serve'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:156:in `fork'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:156:in `serve'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:131:in `block in run'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:125:in `loop'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application.rb:125:in `run'
from /Users/zeeshandar/.rvm/gems/ruby-2.1.5/gems/spring-1.2.0/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/zeeshandar/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/zeeshandar/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'

我不知道我做错了什么,但我认为这是假设工作。任何想法?

1 个答案:

答案 0 :(得分:1)

看起来您的Ancestry版本是1.2.3或者其他东西。更新到新版本看起来应该可以解决这个问题。

<强>的Gemfile

gem 'ancestry', '~> 2.1'