# Strings symbols and databases

**URL:** <https://www.ruby-forum.com/t/strings-symbols-and-databases/107295>\
**Category:** Rails\
**Created:** [June 20, 2007, 8:25am UTC](https://www.ruby-forum.com/t/strings-symbols-and-databases/107295 "2007-06-20T08:25:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 20, 2007, 8:25am UTC](https://www.ruby-forum.com/t/strings-symbols-and-databases/107295/1 "2007-06-20T08:25:38Z")

</div>

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?
