1

I'm using Devise as authenticating solution in Rails and I have a cached fragment :recent_users.

I want this fragment to expire when a new user is registered, changed or removed, so I put in my(manually created) users_controller.rb

class UsersController < ApplicationController
    cache_sweeper :user_sweeper, :only => [:create, :update, :destroy]
...

But my fragment does not expire when new creates or changes.

My user_sweeper contains basic prescriptions

class UserSweeper < ActionController::Caching::Sweeper
observe User

def after_save(user)
   expire_cache(user)
end

def after_destroy(user)
  expire_cache(user)
end

private
  def expire_cache(user)
    expire_fragment :recent_users
  end
end

What am I doing wrong?

Michael Romanenko
  • 571
  • 1
  • 4
  • 12

2 Answers2

1

Problem solved!

I followed this steps and everything works:

$ mkdir app/controllers/users
$ touch app/controllers/users/registrations_controller.rb

In registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController
  cache_sweeper :user_sweeper, :only => [:create, :update, :destroy]    
end

Problem was that Registrations in Devise is a separate controller.

Michael Romanenko
  • 571
  • 1
  • 4
  • 12
  • I also needed to follow a few of the directions here: http://devise.plataformatec.com.br/#getting-started/configuring-controllers – vlasits Sep 19 '13 at 19:56
0

Put this in applications_controller.rb

class ApplicationController < ActionController::Base
    cache_sweeper :user_sweeper, :only => [:create, :update, :destroy]
...
mbinette
  • 5,094
  • 3
  • 24
  • 32
Allen
  • 1