Rails控制器操作具有常见的样板 struct
def update
respond_to do |format|
if @individual.update(individual_params)
format.html { redirect_to @individual, notice: "Individual was successfully updated." }
# if @individual.changed?
render_pdf
# end
else
format.html { render :edit, status: :unprocessable_entity }
end
end
end
然而,我们的目标是-在记录已更新的地方(除了updated_at
属性)-激活将生成PDF的方法.
参考有关dirty的文档,我无法生成对changed?
方法的真实响应.我怀疑这是因为调用方法的时间(if @individual.update
表示记录已经保存,因此清除了污点).
上述内容应该如何写才能达到目标呢?
alternative
a callback after_update_commit
might be an option, however, the rails guide is not explicit as to whether the action is launched when no attributes are updated.