impress/app/models/item_observer.rb

34 lines
870 B
Ruby
Raw Normal View History

class ItemObserver < ActionController::Caching::Sweeper
def after_create(item)
Rails.logger.debug "Item #{item.id} was just created"
expire_newest_items
end
def after_update(item)
Rails.logger.debug "Item #{item.id} was just updated"
expire_cache_for(item)
end
def after_destroy(item)
Rails.logger.debug "Item #{item.id} was just destroyed"
expire_cache_for(item)
end
private
def controller
@controller ||= ActionController::Base.new
end
def expire_cache_for(item)
controller.expire_fragment("items/#{item.id}#item_link_partial")
2012-08-09 21:02:11 -07:00
controller.expire_fragment("items/#{item.id} header")
controller.expire_fragment("items/#{item.id} info")
end
def expire_newest_items
controller.expire_fragment('outfits#new newest_items')
controller.expire_fragment('items#index newest_items')
end
end