代码之家  ›  专栏  ›  技术社区  ›  JP Silvashy Gautam Rege

Rails,在呈现某些内容后更新数据库记录?

  •  1
  • JP Silvashy Gautam Rege  · 技术社区  · 14 年前

    有没有一种方法可以在呈现某个内容之后更新记录,而不必将代码放在我的视图中?

    read 属性为 true . 这样做的最佳实践是什么?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Shadwell    14 年前

    after_filter before_filter

    class MyController << ApplicationController
      after_filter :mark_read
    
      def mark_read
        @message.update_attribute(:read, true)
      end
    end