I am getting the following error, when I try to run my application:
uninitialized constant RegistrationsController::User_serial
In my config/application.rb, I have:
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
In my registrations_controller.rb, I have the following:
class RegistrationsController < Devise::RegistrationsController
........
def create
@user = User.new(params[:user])
user_serial_local = User_serial.new #initialize class defined in lib/my_tools.rb
date_time_local = Date_formatter.new
......
In lib/my_tools.rb, I define some classes:
class User_serial
def self.calculate(first,last)
first_3 = first[0..2]
last_4 = last[0..3]
time = Time.now.to_i
return first_3 + last_4 + time.to_s
end
end
class Date_formatter
def self.datetime
return Time.now.strftime("%Y-%m-%d %H:%M:%S")
end
end
There are a lot of references to overriding a class, and instructions on how to insure that anything placed in the lib folder is included (followed in my code). Why am I getting the error message?
For rails’ magic loading to work it needs to be able to find the file a class/module is defined in based only on the class name.
This in turn means sticking to rails’ naming conventions and putting things where rails expects: UserSerial should be defined in user_serial.rb. You might be able to get User_serial to work as a class name but rails will never look in my_tools.rb for that class.