I have a Product model. My app creates a fragment cache for
mysite.com/products, which triggers the index action (my app is
RESTful). Only admins can edit products, therefore, when adding a new
product, the mysite.com/products should expire.
But I have a problem: my products administration controller is in
admin/products_controller.rb, and therefore stupid Rails expires
admin/products fragment which is not correct.
Here is part of my code:
In the view:
<%- cache(:controller => ‘products’, :action => ‘index’) do -%>
<%- for product in @products -%>
In the admin/products_controller.rb:
cache_sweeper :product_sweeper, :only => [:create, :update, :destroy]
And my sweeper:
class ProductSweeper < ActionController::Caching::Sweeper
expire_fragment(:controller => ‘products’, :action => ‘index’)
How to tell Rails to not be clever, and simply force him to expire
products fragment instead of admin/products?