2012-10-18 85 views
0

我正在寫一個類方法來查找數據庫中的某些數據,但是我得到一個NoMethodError:undefined方法錯誤。我正在使用Datamapper而不是ActiveRecord。這是我的錯誤輸出:返回NoMethodError的類方法:undefined方法Rails

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 

我希望有人可以提供幫助。謝謝。

+0

你如何調用該方法? – Agis

+0

Course.get_courses_starting_in我正在軌道控制檯中測試它。 – Hugs

+2

您是否在啓動控制檯後編寫代碼?重新啓動控制檯並再次檢查。 – Salil

回答

0

您是否在啓動控制檯後編寫代碼?重新啓動控制檯並再次檢查。

相關問題