有没有办法在渲染某些内容后更新记录而不将代码放在我的视图中?
例如,我向用户显示消息,在显示消息后,我想将read
属性更新为true
。这样做的最佳做法是什么?
答案 0 :(得分:2)
在rails 2.3中,您可以使用与after_filter
相同的方式执行before_filter
。所以,例如:
class MyController << ApplicationController
after_filter :mark_read
def mark_read
@message.update_attribute(:read, true)
end
end