mardi 15 décembre 2015

Rails custom class

I'd like to create a global instance of a class that is in a file in /lib. I can access this class and initialize it in my controllers like so:

message_queue = MessageQueue.new

However, I would like to have a global version of this that would persist as long as the rails session is running (This is an experiment. I don't want to use a model for this).

I initialized variables in application.rb by doing:

config.autoload_paths << Rails.root.join('lib')

so that they are global, to make sure the class can be found. However, I get an error: uninitialized constant RPG::Application::MessageQueue (NameError) when I initialize the variable.

How can I make an instance of MessageQueue a global variable I can access everywhere?

Aucun commentaire:

Enregistrer un commentaire