# Bidimensional Array

**URL:** <https://www.ruby-forum.com/t/bidimensional-array/115872>\
**Category:** Rails\
**Created:** [September 29, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/bidimensional-array/115872 "2007-09-29T15:45:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [September 29, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/bidimensional-array/115872/1 "2007-09-29T15:45:31Z")

</div>

Hi,

As I can initialize and add to a bidimensional Array?  
I am mirnado in api and I do not see anything it clear.

I am proving thus, but it gives error me:

$itemlist = [][]  
$itemlist \<\< Item.new(‘name1’,‘value1’)

Thank you very much.

---

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [September 29, 2007, 5:45pm UTC](https://www.ruby-forum.com/t/bidimensional-array/115872/2 "2007-09-29T17:45:56Z")

</div>

You don’t need to declare it as bidirectional. Something like this may  
be what your looking for, if not supplying a little more information  
would help:

$itemlist = []  
$itemlist[0] \<\< Item.new(‘name1’,‘value1’)

This is assuming that Item.new returns an array, that would leave you  
with a multi-dimensional array.

---

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [September 29, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/bidimensional-array/115872/3 "2007-09-29T19:25:08Z")

</div>

Thanks William.  
With $itemlist = [] does not work either. ☹

My total code is this:

require “uri”  
class EstablishmentTypeTemplatesController \< ApplicationController  
def enviaListaItem  
sRedirect = “/establishment\_contents/list?”  
@params[‘item’].each\_pair {|key, value|  
sRedirect \<\< key \<\< “=” \<\< value \<\< “&”  
}  
enc\_url = URI.encode(sRedirect)  
redirect\_to enc\_url  
end  
def select  
if !(params[:addLista]) then  
$itemlist = []  
$itemlist \<\< Item.new(‘Sobre el Bar’,‘1’)  
$itemlist \<\< Item.new(‘DÃ³nde Estamos’,‘1’)  
$itemlist \<\< Item.new(‘Contactar’,‘1’)  
end  
end  
def addItem  
if (params[:nombreItem]) then  
$itemlist \<\< Item.new(params[:nombreItem],‘1’)  
render :action =\> ‘select’, :templateID =\> params[:templateID]  
end  
end  
end

And this it is the error that it gives:

ArgumentError in Establishment type templatesController#select  
wrong number of arguments (2 for 1)  
RAILS\_ROOT: ./script/…/config/…

#{RAILS\_ROOT}/app/controllers/establishment\_type\_templates\_controller.rb:24:in  
`initialize' #{RAILS_ROOT}/app/controllers/establishment_type_templates_controller.rb:24:in`new’  
#{RAILS\_ROOT}/app/controllers/establishment\_type\_templates\_controller.rb:24:in  
`select’

Request  
Parameters: {“templateID”=\>“3”}

Show session dump

* * *

:current\_user: “1”  
flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}

Thanks again.

---

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [September 29, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/bidimensional-array/115872/4 "2007-09-29T19:38:35Z")

</div>

Looks like the constructor for your Item class only takes one  
argument. What is Item ? (and do you really want a global variable?  
that will fall over as soon as you have more than one mongrel or more  
than one user).

Fred

---

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [September 30, 2007, 8:28am UTC](https://www.ruby-forum.com/t/bidimensional-array/115872/5 "2007-09-30T08:28:13Z")

</div>

def select  
if !(params[:addLista]) then  
$itemlist = []  
$itemlist \<\< Item.new(‘Sobre el Bar’,‘1’)  
$itemlist \<\< Item.new(‘Dónde Estamos’,‘1’)  
$itemlist \<\< Item.new(‘Contactar’,‘1’)  
end  
end

Item.new(‘Sobre el Bar’,‘1’) are trouble (ArgumentError)  
You should do:  
Item.new(:name =\> ‘Sobre el Bar’, :number=\>‘1’)  
mean you need describe methods/field names by your model Item.

[http://www.yulia-site.org](http://www.yulia-site.org)

---

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [September 29, 2007, 7:42pm UTC](https://www.ruby-forum.com/t/bidimensional-array/115872/6 "2007-09-29T19:42:40Z")

</div>

Hi, it appears that there’s an issue with the select method. Could you  
post  
it here?  
Thanks,

-Conrad

---

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [September 30, 2007, 8:32am UTC](https://www.ruby-forum.com/t/bidimensional-array/115872/7 "2007-09-30T08:32:54Z")

</div>

def select  
if !(params[:addLista]) then  
$itemlist = []  
$itemlist \<\< Item.new(‘Sobre el Bar’,‘1’)  
$itemlist \<\< Item.new(‘Dónde Estamos’,‘1’)  
$itemlist \<\< Item.new(‘Contactar’,‘1’)  
end  
end

Item.new(‘Sobre el Bar’,‘1’) are trouble (ArgumentError)  
You should do:  
Item.new(:name =\> ‘Sobre el Bar’, :number=\>‘1’)  
mean you need describe methods/field names by your model Item.

/offtop  
donate to Yulia: [http://www.yulia-site.org](http://www.yulia-site.org)

---

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [September 30, 2007, 10:53am UTC](https://www.ruby-forum.com/t/bidimensional-array/115872/8 "2007-09-30T10:53:14Z")

</div>

alexey.Creopolis wrote:

> def select  
> if !(params[:addLista]) then  
> $itemlist = []  
> $itemlist \<\< Item.new(‘Sobre el Bar’,‘1’)  
> $itemlist \<\< Item.new(‘Dï¿½nde Estamos’,‘1’)  
> $itemlist \<\< Item.new(‘Contactar’,‘1’)  
> end  
> end
> 
> Item.new(‘Sobre el Bar’,‘1’) are trouble (ArgumentError)  
> You should do:  
> Item.new(:name =\> ‘Sobre el Bar’, :number=\>‘1’)  
> mean you need describe methods/field names by your model Item.
> 
> /offtop  
> donate to Yulia: [http://www.yulia-site.org](http://www.yulia-site.org)

Thanks to all.

My problem was as you said, that it thought that to add to a list it was  
necessary to make a New of a variable.

Now I have it thus and it works to me

def select  
if !(params[:addLista]) then  
$itemlist = [[‘Sobre el Bar’,‘1’], [‘DÃ³nde Estamos’,‘1’],  
[‘Contactar’,‘1’]]  
end  
end  
[…]  
$itemlist \<\< [params[:nombreItem],‘1’]

Thank you very much.
