我希望每次用户提交投票时,控制器中存储的值都会增加。投票目前正在运作,但投票柜台却没有。我做错了什么?
if cookies[:num_credits].nil?
cookies[:num_credits] = 1
else
cookies[:num_credits] += 1
end
答案 0 :(得分:2)
这最终起作用了:
if cookies[:num_credits].nil?
cookies[:num_credits] = 1
else
current_credits = cookies[:num_credits].to_f
current_credits += 1
cookies[:num_credits] = current_credits
end