我正在更新视图中虚拟属性的值,但这并未反映在模型实例中。
例如:
我的模型.erb
attr_accessor_with_default :hello_world, false
查看.html.erb
<%= @mymodel.hello_world %><br/>
<%
if ( @mymodel.hello_world == false )
@mymodel.hello_world = true
end
%>
<%= @mymodel.hello_world %>
视图输出:
false
true
但是,当我重新加载页面时,会显示相同的输出,它应该是:
true
true
我在编辑表单中看到了上述行为。当我提交表单(带有验证错误)时,它会重新加载(显示错误),但 hello_world 的值没有被更新。
你有什么建议吗? 我应该怎么做才能获得所需的行为?