views:

66

answers:

2

hello i have:

ActiveRecord::Base.connection.execute "UPDATE ventas SET costo_de_compra = #{@nuevo_costo} WHERE id = #{@vid};"

but this updates that column value every time it's recursed, what i want is just to insert that value to the already stablished values in that column... in proper instance i want to add the values to an integer column.

Thanks in advance

A: 

I don't know Rails, but I guess something like this:

ActiveRecord::Base.connection.execute _
"UPDATE ventas SET costo_de_compra = costo_de_compra  + #{@nuevo_costo} _
WHERE id = #{@vid};"
Remus Rusanu
A: 

EDIT: oh, it's an integer column. Updated.

If I understand your question right, you are trying to add to the existing value of an integer column. If you are following rails conventions, you should be able to do something like this:

@venta = Venta.find(@vid)
@venta.costo_de_compra += @nuevo_costo
@venta.save
Ben