返回NoMethodError的类方法:未定义的方法Rails

时间:2012-10-18 09:24:30

标签: ruby-on-rails datamapper ruby-datamapper

我正在编写一个类方法来查找我的数据库中的某些数据但是我得到一个NoMethodError:未定义的方法错误。我使用Datamapper而不是ActiveRecord。这是我的错误输出:

NoMethodError: undefined method `get_courses_starting_in' for Course:Class
    from /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/dm-ar-finders-1.2.0/lib/dm-ar-finders.rb:155:in `method_missing_with_find_by'
    from /Users/hugo/Web Development/Rails/connectedtrips/lib/ct_gems/dm-core-1.2.0/lib/dm-core/model/relationship.rb:372:in `method_missing'
    from /Users/hugo/Web Development/Rails/connectedtrips/lib/ct_gems/dm-core-1.2.0/lib/dm-core/model/property.rb:249:in `method_missing'
    from (irb):24
    from /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
    from /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
    from /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

这是我的班级方法:

def self.get_courses_starting_in
    courses = []
    Course.all.each{ |course| courses << course if course.days_till_course_starts == 7}
    return courses
  end

我希望有人可以提供帮助。感谢。

1 个答案:

答案 0 :(得分:0)

启动控制台后是否编写了代码?重新启动控制台并再次检查。