假设我们在模型中有一个方法
应该在方法本身内部发生"保存"调用,如下面的代码
def result
save! if new_record?
# do some funky stuff here that may also change the model state
# ...
# And calculate the return value
search_result = "foo" # Let's say "foo" is the value we calculated
save! if changed?
search_result # return
end
Run Code Online (Sandbox Code Playgroud)
或者外部观察者(控制者)是否应负责根据需要进行保存?