简体   繁体   English

Rails中未定义方法“作用域”中的NoMethodError(使用祖先gem)

[英]NoMethodError in undefined method `scoped' in rails (using ancestry gem)

I am using the ancestry gem and im testing my model in the console first.When i use 我正在使用祖先宝石并先在控制台中测试我的模型。

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

It inserts data into the database but when i use 它将数据插入数据库,但是当我使用时

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

It gives an error.This is the log 它给出了一个错误。这是日志

  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'

I don't know what im doing wrong but i think this is suppose to work.Any ideas? 我不知道我在做什么错,但是我认为这应该可行。任何想法吗?

It looks like your version of Ancestry is 1.2.3 or something. 看来您的Ancestry版本是1.2.3或类似的版本。 Updating to a new version looks like it should fix that problem. 更新到新版本看起来应该可以解决该问题。

Gemfile 的Gemfile

gem 'ancestry', '~> 2.1'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用祖先gem的未定义方法`child_ancestry&#39; - undefined method `child_ancestry' using ancestry gem Rails-NoMethodError-AccessToFinance:Module的未定义方法“作用域” - Rails - NoMethodError - undefined method 'scoped' for AccessToFinance:Module 先祖宝石说:“……的未定义方法&#39;祖先&#39;” - Ancestry gem says “undefined method `ancestry' for…” 使用“受保护的属性” gem时出现Rails NoMethodError(未定义方法“ id”…) - Rails NoMethodError (undefined method `id'…) while using 'protected attributes' gem 带Rails的嵌套注释的祖先宝石导致未定义的方法错误 - Ancestry Gem for Nested Comments with Rails causing undefined method error 先祖宝石“未定义方法”错误 - Ancestry Gem 'undefined method' error Rails 3 / Bundler gem:Bundler的&#39;undefined method`setup&#39;:Module(NoMethodError)&#39; - Rails 3 / Bundler gem: 'undefined method `setup' for Bundler:Module (NoMethodError)' Rails:错误“ NoMethodError:nil:NilClass的未定义方法&#39;&lt;&#39;”,缺少一些gem吗? - Rails: Error “NoMethodError: undefined method `<' for nil:NilClass”, missing some gem? Rails NoMethodError:未定义的方法 - Rails NoMethodError: Undefined Method Rails 3中未定义的方法/ NoMethodError - Undefined method/NoMethodError in Rails 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM