# Initialize static data from database in application

**URL:** <https://www.ruby-forum.com/t/initialize-static-data-from-database-in-application/112532>\
**Category:** Rails\
**Created:** [August 20, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/initialize-static-data-from-database-in-application/112532 "2007-08-20T18:40:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![procrastinx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@procrastinx](https://www.ruby-forum.com/u/procrastinx)\
**Post date:** [August 20, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/initialize-static-data-from-database-in-application/112532/1 "2007-08-20T18:40:47Z")

</div>

Hi Group ,  
I have a table messages which has some application data which has to  
be used not so frequently. Also the data to - be returned depends on  
the context. The current strategy that i use is something like  
return Message.find\_by\_id().message\_string  
This is not very elegant since i am making a database call for some  
information which is constant throughout the application.  
What i would like to have is that static variables instantiated in  
the Message Model ( and they have to be loaded from the database  
since new messages are added directly to the database ) once the  
application starts and then the return methods can happen at the model  
level instead of a database call.  
I was asking for this procedure since the current process has the  
messages being added directly to the database with the migrations.  
Else , i can go back to manually adding them to the model , but was  
curious to know if there are any other methods.  
Suggestions anyone?

–  
Thanks
