# Symbol as array index error

**URL:** <https://www.ruby-forum.com/t/symbol-as-array-index-error/225963>\
**Category:** Ruby\
**Created:** [August 19, 2007, 11:24am UTC](https://www.ruby-forum.com/t/symbol-as-array-index-error/225963 "2007-08-19T11:24:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nick314](https://www.ruby-forum.com/u/nick314)\
**Post date:** [August 19, 2007, 11:24am UTC](https://www.ruby-forum.com/t/symbol-as-array-index-error/225963/1 "2007-08-19T11:24:53Z")

</div>

I don’t know why this code got Symbol as array index error.  
Please help me out.  
nick314

cl/xmlserial is the library of REXML

require ‘yaml’  
require ‘cl/xmlserial’

class Person  
include XmlSerialization  
attr\_accessor :account, :name, :penalty, :problems, :hash  
def initialize(account, name, penalty=0, problems=0, hash={})  
@account = account  
@name = name  
@penalty = penalty.to\_i  
@problems = problems.to\_i  
@hash = hash  
end

def add\_problem begin\_time, problem, result, submit\_time  
if @hash.has\_key?(problem) and @hash[problem] \<= 0  
return  
end  
# …  
if result == 2  
@penalty += submit\_time - begin\_time  
@problems += 1  
if @hash.has\_key?(problem)  
@penalty += @hash[problem] \* 20\*60  
else  
@hash[problem] = 0  
end  
@hash[problem] \*= -1  
else  
if @hash.has\_key?(problem)  
@hash[problem] += 1  
else  
@hash[problem] = 1  
end  
end  
end

def inspect  
“#@account, #@problems, #@penalty”  
end  
end

# sort criteria =\> high problems, low penalty, lexicographical account

class Person  
include XmlSerialization  
def \<=\>(other)  
if @problems == other.problems  
if @penalty == other.penalty  
return @account \<=\> other.account  
else  
return @penalty \<=\> other.penalty  
end  
else  
return other.problems \<=\> @problems  
end  
end  
end

class ContestBoard  
include XmlSerialization  
attr\_accessor :people, :begin\_time, :problems  
def initialize begin\_time, problems=nil  
@people = []  
@begin\_time = begin\_time  
@problems = problems  
end

def add account, problem, result, submit\_time  
if find(account).nil?  
person = Person.new(account, User.find (account).name)  
person.add\_problem(begin\_time, problem, result, submit\_time)  
@people \<\< person  
else  
index = find(account)  
people[index].add\_problem(begin\_time, problem, result,  
submit\_time)  
end  
end

def find account  
index = 0  
@people.each { |p|  
if p.account == account  
return index  
end  
index += 1  
}  
return nil  
end

def show  
for person in @people  
puts person.inspect  
end  
end

def sort  
@people = @people.sort  
end  
end

class Serialization  
include XmlSerialization  
attr\_accessor :classType, :type  
def initialize classType=ContestBoard, type=“yaml”  
@classType = classType  
@type = type  
end

def serialize obj  
if @type == “yaml”  
return YAML\_serialize obj  
elsif @type == “xml”  
return XML\_serialize(obj)  
end  
end

def unserialize  
if @type == “yaml”  
return YAML\_unserialize obj  
elsif @type == “yaml”  
return XML\_unserialize obj  
end  
end

private  
def YAML\_serialize obj  
return YAML.dump(obj)  
end

def YAML\_unserialize sObj  
return YAML.load(sObj)  
end

def XML\_serialize obj  
return obj.to\_xml  
end

def XML\_unserialize sObj  
doc = REXML::Document.new(sObj);  
return @classType.from\_xml(doc.root )  
end  
end

# …

class ContestsController \< ApplicationController  
def index  
list  
render :action =\> ‘list’  
end

# GETs should be safe (see

[URIs, Addressability, and the use of HTTP GET and POST](http://www.w3.org/2001/tag/doc/whenToUseGet.html))  
verify :method =\> :post, :only =\> [:destroy, :create, :update],  
:redirect\_to =\> { :action =\> :list }

# contest\_board method

def contest\_board  
@now\_contest = Contest.find( get\_now\_contest );  
if !@now\_contest.nil?  
solveinfos = @now\_contest.solveinfos.find(:all, :order =\>  
“created\_at ASC”);  
#solveinfos = @now\_contest.solveinfos.find(:all, :conditions =\>  
“solveStatus = 2”, :order =\> “created\_at ASC”);  
# get many solveinfo  
@board = ContestBoard.new(@now\_contest.from)  
for solveinfo in solveinfos  
@board.add(solveinfo.userID, solveinfo.problemID,  
solveinfo.solveStatus, solveinfo.created\_at );  
end  
@board.sort  
@users = User.find(:all)

```
  #@past_contest = PastContests.new
  #@serialization = Serialization.new(@board)
  #@past_contest.contest_id = @now_contest.id
  #@past_contest.format = 'yaml'
  #@past_contest.serialization = @serialization.serialize
  #@past_contest.save

  puts @board.to_xml
  #@past_contest = PastContests.new
  #@serialization = Serialization.new(ContestBoard, 'xml')
  #@past_contest.contest_id = @now_contest.id
  #@past_contest.format = 'xml'
  #@past_contest.serialization = @serialization.serialize @board
  #@past_contest.save

end

```

end

def contest\_board\_test  
@board = ContestBoard.new  
@board.add(‘nick314’, 1, 1, 10)  
@board.add(‘nick314’, 1, 2, 10)  
@board.add(‘nick314’, 2, 1, 10)  
@board.add(‘nick314’, 2, 1, 10)  
@board.add(‘nick314’, 2, 2, 10)  
@board.sort  
end

# get\_now\_contest method

def get\_now\_contest  
# there won’t be two contests overlayped  
now = Time.now  
for contest in Contest.find(:all)  
if now \>= contest.from and now \< contest.to  
return contest.id  
end  
end  
return nil  
end

# list method

def list  
@contest1 = Contest.find(1)  
@solveinfo = @contest1.solveinfos  
@solved\_problem = @ solveinfo.find(:all)  
# this is wrong  
#@contest1.solveinfos \<\< Solveinfo.find( 221 )  
@contests\_pages, @contests = paginate :contests, :per\_page =\> 10  
end

# show method

def show  
@contests = Contest.find(params[:id])  
end

# new method

def new  
@contests = Contest.new  
end

# create method

def create  
@contests = Contest.new(params[:contests])  
if @contests.save  
flash[:notice] = ‘Contests was successfully created.’  
redirect\_to :action =\> ‘list’  
else  
render :action =\> ‘new’  
end  
end

# edit method

def edit  
@contests = Contest.find(params[:id])  
end

# update method

def update  
@contests = Contest.find(params[:id])  
if @contests.update\_attributes(params[:contests])  
flash[:notice] = ‘Contest was successfully updated.’  
redirect\_to :action =\> ‘show’, :id =\> @contests  
else  
render :action =\> ‘edit’  
end  
end

# destroy method

def destroy  
Contest.find(params[:id]).destroy  
redirect\_to :action =\> ‘list’  
end  
end

---

<div class="post-metadata">

**Author:** ![nick314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nick314](https://www.ruby-forum.com/u/nick314)\
**Post date:** [August 19, 2007, 11:47am UTC](https://www.ruby-forum.com/t/symbol-as-array-index-error/225963/2 "2007-08-19T11:47:56Z")

</div>

On 8/19/07, nick314 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I don’t know why this code got Symbol as array index error.  
> Please help me out.  
> nick314  
> It would be helpfull to tell us where in the code the error occurred.  
> Cheers  
> Robert

---

<div class="post-metadata">

**Author:** ![nick314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nick314](https://www.ruby-forum.com/u/nick314)\
**Post date:** [August 19, 2007, 3:06pm UTC](https://www.ruby-forum.com/t/symbol-as-array-index-error/225963/3 "2007-08-19T15:06:21Z")

</div>

This is the error message.  
I Copy these code out of App/Controller…  
Then it works fine…  
Please help me out.  
And tell me why.  
Thanks a lot.

nick314

TypeError in ContestsController#contest\_board  
/usr/lib/ruby/1.8/rexml/parent.rb:58:in `[]': Symbol as array  
indexRAILS\_ROOT: script/…/config/…

Application Trace | Framework Trace | Full Trace  
/usr/local/lib/site\_ruby/1.8/cl/xmlserial/xmlserial.rb:189:in  
`instance_data_to_xml' /usr/lib/ruby/1.8/rexml/parent.rb:58:in `[]’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/core\_ext/array/conversions.rb:50:in  
`to_xml' (eval):1:in `instance\_data\_to\_xml’  
app/controllers/contests\_controller.rb:175:in  
`contest_board'/usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:189:in `instance\_data\_to\_xml’  
/usr/lib/ruby/1.8/rexml/parent.rb:58:in `[]' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:50:in `to\_xml’  
/usr/local/lib/site\_ruby/1.8/cl/xmlserial/xmlserial.rb:183:in `each' /usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:183:in `instance\_data\_to\_xml’  
/usr/local/lib/site\_ruby/1.8/cl/xmlserial/xmlserial.rb:66:in `to_xml' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:1095:in  
`perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:634:in  
`call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:438:in  
`call' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:619:in  
`perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/rescue.rb:83:in  
`perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process\_without\_session\_management\_support’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/session\_management.rb:114:in  
`process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in  
`dispatch' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in  
`synchronize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in  
`process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in  
`process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in  
`initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:488:in  
`load' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:488:in  
`load' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:342:in  
`new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require' script/server:3/usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:189:in `instance\_data\_to\_xml’  
/usr/lib/ruby/1.8/rexml/parent.rb:58:in `[]' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:50:in `to\_xml’  
(eval):1:in `instance_data_to_xml' /usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:183:in `each’  
/usr/local/lib/site\_ruby/1.8/cl/xmlserial/xmlserial.rb:183:in  
`instance_data_to_xml' /usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:66:in `to\_xml’  
app/controllers/contests\_controller.rb:175:in `contest_board' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:1095:in  
`perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:634:in  
`call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:438:in  
`call' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:619:in  
`perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/rescue.rb:83:in  
`perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process\_without\_session\_management\_support’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/session\_management.rb:114:in  
`process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in  
`dispatch' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in  
`synchronize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in  
`process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in  
`process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in  
`initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:488:in  
`load' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:488:in  
`load' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:342:in  
`new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require’  
script/server:3Request  
Parameters: None

Show session dump

* * *

:return\_url: /contests/contest\_board  
flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Content-Type”=\>“text/html; charset=utf-8”,  
“Cache-Control”=\>“no-cache”}

----- Original Message -----  
From: “Robert D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Sunday, August 19, 2007 5:46 PM  
Subject: Re: Symbol as array index error

---

<div class="post-metadata">

**Author:** ![nick314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nick314](https://www.ruby-forum.com/u/nick314)\
**Post date:** [August 20, 2007, 8:12pm UTC](https://www.ruby-forum.com/t/symbol-as-array-index-error/225963/4 "2007-08-20T20:12:00Z")

</div>

This is the error message.  
I Copy these code out of App/Controller…  
Then it works fine…  
Please help me out.  
And tell me why.  
Thanks a lot.

nick314

TypeError in ContestsController#contest\_board  
/usr/lib/ruby/1.8/rexml/parent.rb:58:in `[]': Symbol as array  
indexRAILS\_ROOT: script/…/config/…

Application Trace | Framework Trace | Full Trace  
/usr/local/lib/site\_ruby/1.8/cl/xmlserial/xmlserial.rb:189:in  
`instance_data_to_xml' /usr/lib/ruby/1.8/rexml/parent.rb:58:in `[]’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/core\_ext/array/conversions.rb:50:in  
`to_xml' (eval):1:in `instance\_data\_to\_xml’  
app/controllers/contests\_controller.rb:175:in  
`contest_board'/usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:189:in `instance\_data\_to\_xml’  
/usr/lib/ruby/1.8/rexml/parent.rb:58:in `[]' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:50:in `to\_xml’  
/usr/local/lib/site\_ruby/1.8/cl/xmlserial/xmlserial.rb:183:in `each' /usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:183:in `instance\_data\_to\_xml’  
/usr/local/lib/site\_ruby/1.8/cl/xmlserial/xmlserial.rb:66:in `to_xml' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:1095:in  
`perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:634:in  
`call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:438:in  
`call' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:619:in  
`perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/rescue.rb:83:in  
`perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process\_without\_session\_management\_support’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/session\_management.rb:114:in  
`process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in  
`dispatch' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in  
`synchronize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in  
`process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in  
`process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in  
`initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:488:in  
`load' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:488:in  
`load' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:342:in  
`new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require' script/server:3/usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:189:in `instance\_data\_to\_xml’  
/usr/lib/ruby/1.8/rexml/parent.rb:58:in `[]' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/array/conversions.rb:50:in `to\_xml’  
(eval):1:in `instance_data_to_xml' /usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:183:in `each’  
/usr/local/lib/site\_ruby/1.8/cl/xmlserial/xmlserial.rb:183:in  
`instance_data_to_xml' /usr/local/lib/site_ruby/1.8/cl/xmlserial/xmlserial.rb:66:in `to\_xml’  
app/controllers/contests\_controller.rb:175:in `contest_board' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:1095:in  
`perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:634:in  
`call_filter' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:438:in  
`call' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in `call\_filter’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:619:in  
`perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/rescue.rb:83:in  
`perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process\_without\_session\_management\_support’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/session\_management.rb:114:in  
`process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in  
`dispatch' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in  
`synchronize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in  
`process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in  
`process_client' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in  
`initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run’  
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in  
`run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:488:in  
`load' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:488:in  
`load' /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:342:in  
`new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39  
/usr/local/lib/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require’  
script/server:3Request  
Parameters: None

Show session dump

* * *

:return\_url: /contests/contest\_board  
flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Content-Type”=\>“text/html; charset=utf-8”,  
“Cache-Control”=\>“no-cache”}

----- Original Message -----  
From: “Robert D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Sunday, August 19, 2007 5:46 PM  
Subject: Re: Symbol as array index error
