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.
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.
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!
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.