我在lib /文件夾中有一個CommonFunctions模塊。我有一個問題模型,其中包括CommonFunctions模塊。現在我試圖訪問CommonFunctions喜歡的函數,如Question.favorite。但是我得到了NoMethodError。我已經包含了代碼。誰能告訴我在哪裏,我做了錯誤Ruby模塊包含問題
錯誤
NoMethodError: undefined method `favorite' for Class:0x00000100e11508
裏面的lib/CommonFunctions.rb
module CommonFunctions
def favorite(object_id)
end
end
內部應用程序/模型/ Question.rb
require 'lib/CommonFunctions.rb'
class Question
extend CommonFunctions
end
我執行下面的代碼腳本/控制檯
Question.favorite(1)
感謝
這是的How do I properly include a module and call module functions from my Rails model?
非常感謝你:) – felix 2010-06-26 21:31:08