2016-02-15 87 views
0

我有rails應用程序,因爲我命名空間需要所有模塊。模塊沒有加載和獲取Name error Uninitialised constant Udp名稱錯誤:未初始化的常量 - Rails命名空間模塊

/app/adapters/Udp/  #Here Udp is the module name 

包含兩個文件。

first.rb

module Udp 
    class First  #First is the class name 
    def self.first_ac 
     "first" 
    end 
    end 
end 

sec.rb

module Udp 
    class Sec 
    def self.sec_ac 
     "sec" 
    end 
    end 
end 

的config/application.rb中

config.autoload_paths += Dir["#{config.root}/app/adapters/**/*"] 

我試圖訪問: Articles_controller

def index 
    msg = Article.invite 
    render text: msg 
end 

Article.rb

def self.invite 
    msg = Udp::First.first_ac 
    msg 
end 

請幫我解決它。

+0

因爲你的文件夾的Udb(注意最後的b)和你的模塊是UDP(注意最後的P)是它不只是?或者是在這個問題上的錯字? – Shadwell

+0

我很抱歉。這是一個打字錯誤。我現在編輯它。 –

回答

0

我解決它通過編輯/config/environments/development.rb如下

config.eager_load = true 
相關問題