From: ChrisH Date: 2007-04-04T23:20:09+09:00 Subject: Re: Problem Extracting Array Values On Apr 4, 10:02 am, Dustin Anderson wrote: > Hi All, > > I'm trying to iterate through an array and pull each value into a view > on my Rails app. The array is stored in a MySQL database. > > The array is in a varchar (string) column named "blocks" with the value: > ["journal", "about", "news"] > > I'm trying to pull each value out one at a time. > > If I try to access the array with something like this...: > <%= @blocks[0] %> > > ..the view returns a numeric value: > 91 > > I'm totally confused as to why I can't extract the values out of the > array. It works fine in IRB: > irb(main):004:0> @blocks = ["journal", "about"] > => ["journal", "about"] > irb(main):005:0> @blocks[0] > => "journal" > irb(main):006:0> > > Is there some reason why I can't get the "journal" string out of the > array? > > Thanks in advance for your help! > Dustin > > -- > Posted viahttp://www.ruby-forum.com/. As you say, its stored as a String, and String defines [] to return the ASCII value of the character at the given index. If you put 91.chr into IRB you'll see it is the '[' character. You need to convert your String into an actual array before you can access each element. Maybe: eval(@blocks)[0] Cheers Chris