hacer un insert en un ciclo

K

Karla Guzman

Hola.

quiero hacer un insert a mi base de datos mediante un ciclo
es decir que en el cliclo este la columna y el valor. de los datos
alguien sabe si se puede?


inventario_tem = InventarioTem.new(
while @y < @datostotales.length do

@columna => @datostotales[@y])

@y+=1
end
inventario_tem.save


muchas gracias
 
A

andrew mcelroy

2010/3/1 Karla Guzman said:
Hola.

quiero hacer un insert a mi base de datos mediante un ciclo
es decir que en el cliclo este la columna y el valor. de los datos
alguien sabe si se puede?
This doesn't seem very efficient.
Second, could you please speak in english. Even with google translate,
the technical message
is lost.

Andrew McElroy
inventario_tem =3D InventarioTem.new(
=A0while @y < @datostotales.length do

=A0 =A0 =A0@columna =3D> @datostotales[@y])

=A0 =A0@y+=3D1
=A0end
inventario_tem.save


muchas gracias
 
A

andrew mcelroy

This doesn't seem very efficient.
Second, could you please speak in english. Even with google translate,
the technical message
is lost.
por favor tu habla Ingl=E9s.

Andrew McElroy
inventario_tem =3D InventarioTem.new(
=A0while @y < @datostotales.length do

=A0 =A0 =A0@columna =3D> @datostotales[@y])

=A0 =A0@y+=3D1
=A0end
inventario_tem.save


muchas gracias
 
R

Ryan Davis

quiero hacer un insert a mi base de datos mediante un ciclo
es decir que en el cliclo este la columna y el valor. de los datos
alguien sabe si se puede?


inventario_tem = InventarioTem.new( # OPEN 1
while @y < @datostotales.length do # OPEN 2

@columna => @datostotales[@y]) # CLOSE 1

@y+=1
end # CLOSE 2
inventario_tem.save

([)]

No entiendo.
 
R

Ryan Davis

quiero hacer un insert a mi base de datos mediante un ciclo
es decir que en el cliclo este la columna y el valor. de los datos
alguien sabe si se puede?


inventario_tem = InventarioTem.new( # OPEN 1
while @y < @datostotales.length do # OPEN 2

@columna => @datostotales[@y]) # CLOSE 1

@y+=1
end # CLOSE 2
inventario_tem.save

([)]

No entiendo.
 
X

Xavier Noria

2010/3/2 Karla Guzman said:
quiero hacer un insert a mi base de datos mediante un ciclo
es decir que en el cliclo este la columna y el valor. de los datos
alguien sabe si se puede?


inventario_tem =3D InventarioTem.new(
=C2=A0while @y < @datostotales.length do

=C2=A0 =C2=A0 =C2=A0@columna =3D> @datostotales[@y])

=C2=A0 =C2=A0@y+=3D1
=C2=A0end
inventario_tem.save

Eso asi mismo no funciona, te daria una alternativa pero sin mas
detalles no cuadra mucho que @columna sea fijo.

Esta es una lista en ingles de todos modos, si no sabes ingles por
favor envia tu consulta a la lista ror-es.
 
B

Brian Candler

Karla said:
inventario_tem = InventarioTem.new(
while @y < @datostotales.length do

@columna => @datostotales[@y])

@y+=1
end
inventario_tem.save

I am guessing that what you want to do is this:

datostotales = {"foo"=>123, "bar"=>456"}
inventario_tem = InventarioTem.new(datostotales)
inventario_tem.save

OR:

columna = ["foo", "bar"]
datostotales = [123, 456]
inventario_tem = InventarioTem.new
columna.each_with_index do |col,i|
inventario_tem.send("#{col}=", datostotales)
end
inventario_tem.save

or you can combine the two like this:

columna = ["foo", "bar"]
datostotales = [123, 456]
inventario_tem =
InventarioTem.new(Hash[*columna.zip(datostotales).flatten])
inventario_tem.save
 
K

Karla Guzman

Brian said:
I am guessing that what you want to do is this:

datostotales = {"foo"=>123, "bar"=>456"}
inventario_tem = InventarioTem.new(datostotales)
inventario_tem.save

OR:

columna = ["foo", "bar"]
datostotales = [123, 456]
inventario_tem = InventarioTem.new
columna.each_with_index do |col,i|
inventario_tem.send("#{col}=", datostotales)
end
inventario_tem.save

or you can combine the two like this:

columna = ["foo", "bar"]
datostotales = [123, 456]
inventario_tem =
InventarioTem.new(Hash[*columna.zip(datostotales).flatten])
inventario_tem.save



Thanks Brian
your explanation was very helpful
And sorry for not writing in english, I am very distracted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top