[Ror-es] Añadir en una lista
Zaid Dd
ruby-forum-incoming at andreas-s.net
Tue Sep 25 14:24:13 GMT 2007
Imobach González Sosa wrote:
> On Tue, Sep 25, 2007 at 02:19:02PM +0200, Javier Vidal Postigo 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
--
Posted via http://www.ruby-forum.com/.
More information about the Ror-es
mailing list