Tag: Rails/オブザーバー
class ListSweeper < ActionController::Caching::Sweeper observe List, Item #監視したいモデル(この場合、List、Itemモデルが保存された後処理が走る) def after_save(record) list = record.is_a?(List) ? record : record.list expire_page(controller: "lists", action: %w( show public feed ), id: list.id) expire_action(controller: "lists", action: "all") list.shares.each { |share| expire_page(controller: "lists", action: "show", id: share.url_key) } end end
class ListsController < ApplicationController caches_action :index, :show, :public, :feed cache_sweeper :list_sweeper, only: [ :edit, :destroy, :share ] end