Forum: Ruby on Rails Storing static info in table or model?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Per D. (Guest)
on 2005-12-28 09:51
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?
subimage interactive (Guest)
on 2005-12-28 10:06
(Received via mailing list)
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.
Ed W. (Guest)
on 2005-12-28 13:36
(Received via mailing list)
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
Per D. (Guest)
on 2005-12-29 00:05
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?
This topic is locked and can not be replied to.