def addItem
if (params[:nombreItem]) then @itemlist += [Item.new(params[:nombreItem])]
render :action => ‘select’, :templateID => params[:templateID]
end
end
Es que @itemlist se est� creando nuevo en cada petici�n HTTP a la
aplicaci�n. Tendr�s que guardar @itemlist en la sesi�n o en la base de
datos.
On Tue, Sep 25, 2007 at 02:19:02PM +0200, Javier Vidal P. wrote:
Es que @itemlist se est� creando nuevo en cada petici�n HTTP a la
aplicaci�n. Tendr�s que guardar @itemlist en la sesi�n o en la base de
datos.
S�, ese parece el problema.
Por cierto, esto es un poco anti-ruby:
@itemlist += [Item.new(params[:nombreItem])]
Mejor algo como esto:
@itemlist << Item.new(params[:nombreItem])]
Saludos.
MuchÃsimas gracias
El problema venÃa por ahÃ. Ahora hago esto en la definición
def initialize
super
if ($itemlist.first == “”)
$itemlist << Item.new(‘1’)
<< Item.new(‘2’)
<< Item.new(‘3’)
end
end
Y luego lo añado asÃ:
def addItem
if (params[:nombreItem]) then
$itemlist << Item.new(params[:nombreItem])
end
end
Con esto sólo la primera petición http inicializa $itemlist y el resto
añade.
Lo dicho. MuchÃsimas gracias
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.