我在/ lib
中有一个模块Module Info
class Inf
def getNum
num = Array.new
num.push(2,1)
end
end
在控制器informations_controller中,我有'require Info'和以下代码:
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 =>'informations #index'”可能会丢失什么?
答案 0 :(得分:4)
它应该是module
而不是模块,你也应该命名文件info.rb
,并且你应该确保lib在config/application.rb
config.autoload_paths += %W(#{config.root}/lib)
所以它应该是这样的lib/info.rb
:
module Info
class Inf
...
end
end