"Can't convert string to number" - error

Hi,
I have a Model for my_table table
which serialises a column named serialised_column
serialised_column contains an array object, which contains hash objects
something like
serialised_column = [{‘name’ => ‘this’}, {‘name’ => ‘that’}]

the code for model is something like this

class MyTable < ActiveRecord::Base
set_table_name ‘my_table’
serialize :serialised_column
end

and a controller which access the data
class ShowController < ApplicationController
def show
s = MyTable.find(:all, :conditions => [‘some conditions’])
if s.size != 0
@s = []
s.serialised_column.each { |s|
@s << [‘name’ => s[‘name’]]
}
end #if
end #def
end #class

in view the show.rhtml file is something like
<%# considering size of s is not zero
%>
<%= @s[0][‘name’] %>

now when I run this file, I get an TypeError exception, which says
‘can’t
convert String into Integer’
why is so? I’m not casting a string to intger, and neither want it to
happen!

you’re pushing arrays onto @s: @s << [‘name’ => s[‘name’]]

with your current structure you’d have to access them like
@s[0][0]['name]

maybe instead you can just push hashes: @s << {‘name’ => s[‘name’]}

Thanks, I got it. Its working now. thanks again.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs