Question

Basically, I upgraded a 1.8.7@rails2 app to 1.9.3@rails3.2

When trying to use .each_pair on a serialized hash, I end up getting

syntax error, unexpected ',', expecting keyword_end
       @measure.coefficients.each_pair |key, value|

When trying to access the rails console to load up that measure.coefficients, it gives me a string. Which if I try running YAML.load(serialized_string) in either "psych' or 'syck' as instructed by the following answer rails error, couldn't parse YAML

I end up getting

ArgumentError: syntax error on line 21, col 5: `'
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/syck.rb:135:in `load'

Similar result when using 'psych' engine. Anyclue?

Here is a sample of the hash in string format:

"--- !map:HashWithIndifferentAccess \n\"1092\": \"\"\n\"869\": \"\"\n\"1039\": \"\"\n\"2492\": \"\"\n\"1389\": \"\"\n\"1200\": \"\"\n\"600\": \"\"\n\"1928\": \"\"\n\"1767\": \"\"\n\"1498\": \"\"\n\"899\": \"\"\n\"711\": \"\"\n\"1124\": \"\"\n\"1312\": \"\"\n\"1500\": \"\"\n\"900\": \"\"\n\"1152\": \"\"\n\"1232\": \"\"\n\"1340\": \"\"\n\"1420\": \"\"\n\"123"
Was it helpful?

Solution

When you actually print the value, it yields:

--- !map:HashWithIndifferentAccess 
"1092": ""
"869": ""
"1039": ""
"2492": ""
"1389": ""
"1200": ""
"600": ""
"1928": ""
"1767": ""
"1498": ""
"899": ""
"711": ""
"1124": ""
"1312": ""
"1500": ""
"900": ""
"1152": ""
"1232": ""
"1340": ""
"1420": ""
"123

Which is clearly not valid YAML, as it ends with a unterminated string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top