I have a module in lib directory with the name “Transpo.rb”:
module Transpo
class FT
def getCities
...
end
end
end
And in the controller I have
require 'Transpo.rb'
class TranspoController < ApplicationController
def index
@transpo = Transpo::FT.getCities()
respond_to do |format|
format.html # index.html.erb
format.json { render json: @transpo }
end
end
But when I run “http://localhost:3000/transpor” always gives the error:
NoMethodError in TranspoController#index
undefined method `getCities' for Transpo::FT:Class
Why? I’ve already set the auto_load lib in application.rb but continue with the same problem.
getCitiesis defined as an instance method, but you are calling it as a class method.Either create an instance with something like
instance = Transpo::FT.new, or change the definition ofgetCitiesto bedef self.getCitiesto make it into a class method.