# Storing static info in table or model?

**URL:** <https://www.ruby-forum.com/t/storing-static-info-in-table-or-model/51217>\
**Category:** Rails\
**Created:** [December 28, 2005, 8:51am UTC](https://www.ruby-forum.com/t/storing-static-info-in-table-or-model/51217 "2005-12-28T08:51:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pernod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@pernod](https://www.ruby-forum.com/u/pernod)\
**Post date:** [December 28, 2005, 8:51am UTC](https://www.ruby-forum.com/t/storing-static-info-in-table-or-model/51217/1 "2005-12-28T08:51:10Z")

</div>

Hi, what are your thoughts on where and how to store static information  
like for example a countries list?

I can’t decide whether I should store it as a table called Countries in  
the database or just create a non active record model that just lists  
the countries in a hard-coded array in the model file.

Is one better than the other?

---

<div class="post-metadata">

**Author:** ![pernod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@pernod](https://www.ruby-forum.com/u/pernod)\
**Post date:** [December 28, 2005, 9:06am UTC](https://www.ruby-forum.com/t/storing-static-info-in-table-or-model/51217/2 "2005-12-28T09:06:09Z")

</div>

I keep mine in the DB - just in case you want to provide a way for your  
end  
users to change it later on. Besides, what’s the point of storing data 2  
separate places? Seems like a waste of time to me.

---

<div class="post-metadata">

**Author:** ![pernod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@pernod](https://www.ruby-forum.com/u/pernod)\
**Post date:** [December 28, 2005, 12:36pm UTC](https://www.ruby-forum.com/t/storing-static-info-in-table-or-model/51217/3 "2005-12-28T12:36:52Z")

</div>

Per Djurner wrote:

> Hi, what are your thoughts on where and how to store static information  
> like for example a countries list?
> 
> I can’t decide whether I should store it as a table called Countries in  
> the database or just create a non active record model that just lists  
> the countries in a hard-coded array in the model file.

If you have lots of them then a common optimisation is to create a  
“lookups” table with schema perhaps like:

id int  
label varchar  
order int  
value int

Then you can stuff several looks in a single table which encourages you  
to actually do lookup values properly as well!

Ed W

---

<div class="post-metadata">

**Author:** ![pernod](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@pernod](https://www.ruby-forum.com/u/pernod)\
**Post date:** [December 28, 2005, 11:05pm UTC](https://www.ruby-forum.com/t/storing-static-info-in-table-or-model/51217/4 "2005-12-28T23:05:15Z")

</div>

subimage: it would not be in 2 places, the country list (or whatever it  
might be) would go in a table OR directly in the model RB file as an  
array. One advantage to having outside of the database could be to limit  
JOINS in SELECTs. Also, I have no end users, I am the end user myself 🙂

Ed: while a lookup table that stores all kinds of stuff like that could  
increase performance I don’t find it very “elegant”.

What do you guys do you for data that belongs to another object, like  
for example if you have a “users” table and need to store some simple  
user types like admin, guest etc. Do you store it as a table in the  
database, ie “types”, or just as an array hard coded in the user.rb  
file? (in both solutions there would be a “type\_id” in the “users”  
table.

Anyone have any more thoughts on this topic?
