mongoid NoMethodError(未定义的方法`all' for Complex:Class)

时间:2014-02-14 10:32:42

标签: ruby-on-rails mongoid

我是rails的新手...... mongoid模型的简单脚手架正在抛出NoMethodError。

班级代码:

class Complex
    include Mongoid::Document

    field :name, type: String
end

控制器代码:

def index
    @complexes = Complex.all #this is the offending line?
end

GEMFILE(摘录):

...
gem 'rails', '4.0.2'
gem 'mongoid', github: 'mongoid/mongoid'
...

1 个答案:

答案 0 :(得分:1)

在ruby中(至少> = 1.8.6)Complexdefined by the language类,因此当您引用Complex.all时,它会查找complex.c中定义的类在ruby源代码而不是你的类。