开发者

Rails, update a database record after something has been rendered?

Is there way to update a record after something has been rendered without putting the code in my view?

For example I'm displaying messages to my users, and after the messages have been displayed I want to update the read a开发者_开发问答ttribute to true. What would be the best practice for doing this?


In rails 2.3 you can do a after_filter in much the same way you would do a before_filter. So, for example:

class MyController << ApplicationController
  after_filter :mark_read

  def mark_read
    @message.update_attribute(:read, true)
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜