Private method in controller

Hi!

I have two controllers. Number one has this private method:

private

def clean_balance_cache
#Expire the cache for the module right
expire_fragment(:controller => ‘application’, :action => ‘balans’)
end

Is there a way I can call this method in controller #2? I tried adding
this method to the application helpers. But that didn’t work.
expire_fragment can’t be used in a helper. It’s an unknown method
there.

Thank in advance!

LeonB schrieb:

Is there a way I can call this method in controller #2? I tried adding
this method to the application helpers. But that didn’t work.
expire_fragment can’t be used in a helper. It’s an unknown method
there.

Thank in advance!

Hi Leon,

just write a small lib, for example

./lib/cache_helper.rb:

can be used everywhere…

module CacheHelper
def self.expire_balance_cache(controller)
controller.expire_fragment(:controller => ‘application’,
:action => :balance)
end
# or as instance method
def expire_balance_cache
expire_fragment(:controller => ‘application’,
:action => :balance)
end
end

./app/controllers/balances_controller.rb
include CacheHelper # unless you want to keep your controller clean

def update
#…
if self.kind_of? CacheHelper
# do this if you included CacheHelper
expire_balance_cache
else
# do this to keep your controller clean
CacheHelper.expire_balance_cache(self)
end
#…
end

Regards
Florian

Thanks Florian! Gonna try that.