因此,我试图在update方法的控制器中手动设置@button_finish_div的@button_finish_div属性。基本上,如果percurso attibute的值在更新之前为false,在更新后为true,则我希望将percurso_time设置为当前日期时间。然而,即使我的代码运行时没有错误,当我检查rails控制台上的值时,我发现如果那个percurso_time仍然是零的话。我做错什么了吗?
def update
before_percurso = @button_finish_div.percurso
if @button_finish_div.update(button_finish_div_params)
after_percurso = @button_finish_div.percurso
if before_percurso == false && after_percurso == true
@button_finish_div.percurso_time = DateTime.now
end
end
end发布于 2015-07-28 19:25:47
只要将值赋值给它,就需要像@button_finish_div.save那样在赋值后保存它。
或者您可以使用update_attribute或update_column来更新它。
https://stackoverflow.com/questions/31685182
复制相似问题