James Blot
James Blot

Reputation: 3

NoMethodError rails

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.

Upvotes: 0

Views: 556

Answers (1)

x1a4
x1a4

Reputation: 19485

getCities is 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 of getCities to be def self.getCities to make it into a class method.

Upvotes: 2

Related Questions