Bidimensional Array

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.

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.

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

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:innew’
#{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.

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

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

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

-Conrad

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

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

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.

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