1

I have created a simple module and placed it in the lib directory and have included in the controller file.

below is the controller code.

class UserController < ApplicationController
  include Departments
  def create
    user_data = Hash.new
    user_data["data"] = "hello world!"
    user_data["price"] = 12
    render :json => user_data
  end
end

when i try to execute it i see the below error

ActionController::RoutingError (uninitialized constant UserController:: Departments):

I have searched forums and see that adding

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

solves the issue, but it did not in my case. I am using Rails 4.2.7.1 and ruby ruby 1.9.3p547.

Can anyone point out what could be the issue, Thanks.

opensource-developer
  • 2,826
  • 4
  • 38
  • 88

1 Answers1

2

I had the naming convestion wrong, i created a sub directory under the lib folder by the name of my module and then created the file with the class name.rb and it worked.

Reference: "Uninitialized constant" error when including a module

Community
  • 1
  • 1
opensource-developer
  • 2,826
  • 4
  • 38
  • 88