views:

23

answers:

2

I am trying to update a record. Am using the following code.

Proddiscount.update({:prodid => params[:id]}, {:discount=>params[:discount]})

Query Im trying to have is:

update proddiscount set discount = '' where prodid = ''
A: 

How about doing this:

@prod = Proddiscount.find(:first, :conditions => {prodid => params[:id]})
@prod.update_attributes({:discount=>params[:discount]})
marcgg
It kinda depends on what "prodid" exactly is, like asked @klew
marcgg
A: 

If prodif is not a primary key, use update_all (read more here)

Proddiscount.update_all("discount = #{params[:discount]}", ["prodid = ?", params[:prodid])

But it won't trigger validations.

klew