2012-05-07 45 views
3

我在/ lib目錄路由錯誤「未初始化的常量信息」

Module Info 
class Inf 

    def getNum 
    num = Array.new 

    num.push(2,1) 

    end 

end 

在informations_controller我有「要求信息」控制器模塊和後續代碼:

def index 
    @informations = Info::Inf.getNum().num 

    respond_to do |format| 
     format.html # index.html.erb 
     format.json { render json: @informations } 
    end 
    end 

但它總是給錯誤

Routing Error 

uninitialized constant Info 

由於路由器我已經定義了「root:to =>'信息#index'」有什麼可能會丟失?

+0

你的模塊文件是否確實有'Module Info'(大寫M)? –

+0

而且它真的沒有'結束' –

+0

是的,你們倆都是對的!謝謝 –

回答

4

應該module不模塊,你也應該命名文件info.rb,你也應該確保庫在一個auto_load路徑在config/application.rb

config.autoload_paths += %W(#{config.root}/lib) 

所以它應該是這樣的lib/info.rb

module Info 
    class Inf 
    ... 
    end 
end 
+0

至少可以投票了 –

相關問題