# Loading data from yml produces strange result?

**URL:** <https://www.ruby-forum.com/t/loading-data-from-yml-produces-strange-result/141609>\
**Category:** Rails\
**Created:** [June 27, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/loading-data-from-yml-produces-strange-result/141609 "2008-06-27T17:20:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![traceyz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@traceyz](https://www.ruby-forum.com/u/traceyz)\
**Post date:** [June 27, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/loading-data-from-yml-produces-strange-result/141609/1 "2008-06-27T17:20:29Z")

</div>

I have a yml file of states of the US and Canada. I am loading them  
into a State model.  
State is defined with a migration  
t.column :name, :string  
t.column :abbrev :string

In my file states.yml, I have entries of this form  
massachusetts:  
name: Massachusetts  
abbrev: MA

then I have a migration that loads the state information

directory = File.join(File.dirname( **FILE** ), “dev\_data”)  
Fixtures.create\_fixtures(directory, “states”)

Everything works as expected, until I try to load the data for Ontario  
the yml entry is  
ontario:  
name: Ontraio  
abbrev: ON

When I run this, the database entry for the Ontario abbreviation  
becomes “1”, a string with the character 1

That isn’t what I want. I have managed to work around this by using  
the abbreviation ONE, and then taking the first two characters with  
slice(0,2) whenever I want an abbreviation.

However, that seems like a band-aid.

ON is perhaps a reserved word, or triggering some behavior I don’t  
understand ?

Any help or insight would be appreciated.

I would like Ontario to have the two character abbreviation ON

---

<div class="post-metadata">

**Author:** ![traceyz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@traceyz](https://www.ruby-forum.com/u/traceyz)\
**Post date:** [June 27, 2008, 5:29pm UTC](https://www.ruby-forum.com/t/loading-data-from-yml-produces-strange-result/141609/2 "2008-06-27T17:29:51Z")

</div>

On Fri, 2008-06-27 at 08:19 -0700, mtz wrote:

> understand ?
> 
> Any help or insight would be appreciated.
> 
> I would like Ontario to have the two character abbreviation ON

* * *

try enclosing it in quotes…  
abbrev: ‘ON’

Craig

---

<div class="post-metadata">

**Author:** ![traceyz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@traceyz](https://www.ruby-forum.com/u/traceyz)\
**Post date:** [June 27, 2008, 5:30pm UTC](https://www.ruby-forum.com/t/loading-data-from-yml-produces-strange-result/141609/3 "2008-06-27T17:30:26Z")

</div>

On 27 Jun 2008, at 16:19, mtz wrote:

> However, that seems like a band-aid.
> 
> ON is perhaps a reserved word, or triggering some behavior I don’t  
> understand ?

I think yaml recognises certain pairs as being booleans (true/false  
etc…). You can defeat that by putting the value in quotes.

Fred

---

<div class="post-metadata">

**Author:** ![traceyz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@traceyz](https://www.ruby-forum.com/u/traceyz)\
**Post date:** [June 27, 2008, 5:53pm UTC](https://www.ruby-forum.com/t/loading-data-from-yml-produces-strange-result/141609/4 "2008-06-27T17:53:51Z")

</div>

GREAT !

That worked. Thanks.

On Jun 27, 11:29 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
