0

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

Mohamed Kamal
  • 357
  • 1
  • 2
  • 10

1 Answers1

0

I might be wrong but just a wild guess. You're including Notifications module (in this specific code - notifications module has no method group_actions)

What I see is that You use scope of Notifications::GroupActions.do_something.


Guess 1: Inside controller also include GroupActions


Guess 2: Inside Notofications module add another module

module Notifications
  module GroupActions
    def self.do_something

Guess 3:

Try to inherit.

module Notifications < GroupActions

or

module GroupActions < Notifications

Hope that any of these solutions will help.

If not, sorry :)