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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -