I'm using ruby 2.1.5 and rails 4.1 in the following folder structure:
- lib/
- notifications/
- notifications.rb
- group_actions.rb
# notifications.rb
module Notifications
end
# group_actions.rb
class GroupActions
self.do_something
end
# inside a controller
class Api::V1::PostsController < Api::BaseController
include Notifications
.
.
.
def create
Notifications::GroupActions.do_something
end
.
.
.
end
I also added this line in "config/application.rb" to autoload my module
# config/application.rb
config.autoload_paths += %W(#{config.root}/lib/notifications)
This works perfectly SOMETIMES, and other times breaks and raises error "Uninitialized constant Notifications::GroupActions"
This is inconsistent, it works in a request and raises this error in following!!! ... it might work for days and break for hours and return again working !!!
I noticed that it always works on the first request after restarting the server if this hint helps.
please help