inboulder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-20 06:25 UTC
Strings symbols and databases
What is the preferred method of saving a hash with symbols as keys to the db? I tried to find this addressed in the archives, already, but came up empty. Since <%= text_field %> creates hashes with symbols by default, what''s the best way to save them? It appears ruby sticks yaml in a string field in the db like "--- :vocabulary" if you save a hash key to db. Is is good style to do something like this to save a hash or is there a more preferred way? score_hash.each do | key, value | score = Score.new score.result = @result score.name = key.to_s score.value = value score.save! end Also, when reconstructing the hash later, is it wise to convert back to symbols (using intern) or just treat as strings? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---