我有我的應用安裝程序在視頻完成觀看時運行ajax。 ajax在下面調用User#操作。問題在於,它在第一次運行時會起作用並添加{「timestamp」=>「1」},但它永遠不會更新爲{「timestamp」=>「1,1」}。有什麼我失蹤?我可以不更新hstore散列中的值嗎?在hstore中爲Rails應用添加哈希值
# Increases User's workouts after video is watched
def increase_workouts
@user = current_user
if logged_in?
if @user.newworkouts[Time.now.strftime("%Y%m%d").to_sym] == nil
@user.newworkouts[Time.now.strftime("%Y%m%d").to_sym] = "0"
end
@user.newworkouts[Time.now.strftime("%Y%m%d").to_sym] += "," + "1"
@user.save
render(json: { message: "Workouts increased" }, status: :ok) and return
else
render(json: { message: "Workouts increased" }, status: :ok) and return
end
end