How to update specific fields?


#1

I can’t figure this out. I just want to update two
fields in the database:

def vote

yes, I need to “to_i” these values!

@id = @params[“id”]
@vote = @params[“vote”]

doesn’t work - not a class method

#Item.update_attributes {[“vote_count=vote_count+1,
vote_total=vote_total + ?”, @vote]}

how to update vote_total by X?

#Item.increment_counter “vote_count”, @id
#Item.increment_counter “vote_total”, @id

error: undefined method `stringify_keys!’ for

#Item.update @id, [“vote_count=vote_count+1,
vote_total=vote_total + ?”, @vote]

error: undefined method `stringify_keys!’ for

“vote_count=vote_count+1, vote_total=vote_total +
5”:String
#Item.update @id, “vote_count=vote_count+1,
vote_total=vote_total + #{@vote}”

error: undefined method `+’ for :vote_count:Symbol

Item.update @id, {:vote_count => :vote_count + 1,
:vote_total => :vote_total + @vote }

flash[:notice] = “vote saved!”

redirect_to :action=>‘item’, :id=>@params[“id”]
end

BTW, does the “update” method first retrive the item,
update it, then retrive it again? If so, definitely
doesn’t seem efficient if all you want to do is update
something.

thanks,
csn


Yahoo! Mail - PC Magazine Editors’ Choice 2005
http://mail.yahoo.com