所以我试图在更新方法的控制器中手动设置@button_finish_div的percurso_time属性。基本上如果percurso attibute的值在之前更新并且之后为true之前为false,我想将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
答案 0 :(得分:1)
您只需为其分配值,您需要在分配后保存它
@button_finish_div.save
或者您可以使用update_attribute
或update_column
进行更新。