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? -- Posted via http://www.ruby-forum.com/.
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. On 12/27/05, Per Djurner <per.djurner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. > > Is one better than the other? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- seth at subimage interactive http://www.subimage.com/sublog/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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
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? -- Posted via http://www.ruby-forum.com/.