路由错误“未初始化的常量信息”

时间:2012-05-07 14:20:06

标签: ruby-on-rails ruby-on-rails-3

我在/ 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'”可能会丢失什么?

1 个答案:

答案 0 :(得分:4)

它应该是module而不是模块,你也应该命名文件info.rb,并且你应该确保lib在config/application.rb

中的auto_load路径中
config.autoload_paths += %W(#{config.root}/lib)

所以它应该是这样的lib/info.rb

module Info
  class Inf
    ...
  end
end