activerecord - Rails save record second time -


i have function :

def vote     story.increment_counter(:vote, params[:id]) end 

first database , see : vote = 2. when refresh page database again see : vote = 4.

second try :

def vote     story = story.find_by_id(params[:id])     @test = story.vote     @test2 = @test.to_i + 1     story.vote = @test2.to_i     story.save end 

in viem have result : @test = 2, @test2 = 3, in database vote = 4.

when use +5 have in database +10 votes.

i use ruby 4.

thanks yours help.


Comments