Fernando Maymone
Fernando Maymone

Reputation: 355

Why my Module is not being loaded in Rails?

I have an application that runs perfectly on my OSX environment. Now Im creating a Ubuntu env from scratch and having a weird class loading issue on my Rails application.

Inside my app/models/MDMS.rb I have

class MDMS
  include HTTParty

  base_uri APP_CONFIG.mdms_url

  def self.ip2location(ip)
    Rails.cache.fetch("MDMS#ip2location(#{ip || 'empty'})", expires_in: 15.days) do
      request("/api/v1/ip2location", { ip: ip })[:data]
    end
  end

And in my application_controller I have a call for this model. Like this:

 if @zip.blank?
    byebug
    #guess from IP
    #r = MDMS.ip2location(request.remote_ip)
    r = MDMS.ip2location("216.189.182.112")
    @zip = session[:zip]  = r['zip_code']
    update_user_zip_attributes(r)
    if [email protected]?
      set_legacy_zip_cookie(r['zip_code'])
    end
  end

The problem is. When I try to run it I got an error:

NoMethodError (undefined method `ip2location' for MDMS:Module):
  app/controllers/application_controller.rb:90:in `current_zip'

So, I dont know why this is happening. Maybe a classloader issue? Someone have ideas on what to try to solve this?

Thank You

Upvotes: 0

Views: 56

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

Inside my app/models/MDMS.rb I have

Your files should be named in snake_case. In this particular case, it should be named mdms.rb

Upvotes: 2

Related Questions