Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails global array

I want to instantiate an array that is accesible trough all the application, the array may change while the application is running but it will be re-generated when the application starts again.

I have though about putting that array in the ApplicationController but it will die once the request is over or not ?; and I just need it to populate it once every time the app starts running not every time a controller action is called.

The array is populated from the database and that has to be already loaded.

Thanks in advance for any guidance.

like image 559
Salvador Aceves Avatar asked Dec 27 '22 23:12

Salvador Aceves


1 Answers

Create a file inside you config/initializers called whatever-you-want.rb and place you code there.

THIS_IS_AN_ARRAY = [1,2,3,4]

You should then be able to access THIS_IS_AN_ARRAY all over your application.

like image 83
Linus Oleander Avatar answered Jan 12 '23 04:01

Linus Oleander