Routing error "uninitialized constant Info"

I have a module in / lib

Module Info
class Inf

  def getNum
    num = Array.new

    num.push(2,1)

  end

end

In the informations_controller controller, I have "require Info" and the following code:

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

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

But he always gives an error

Routing Error

uninitialized constant Info

Since the router I defined "root: to =>" information # index ", what might be missing?

+3
source share
1 answer

it must be modulenot Module, and you must also name the file info.rb, and you must also be sure that lib is in the auto_load path inconfig/application.rb

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

so there should be something like this lib/info.rb:

module Info
  class Inf
    ...
  end
end
+4
source

All Articles