Expire_action in model possible

Hi all,

Is it possible to use expire_action in a model?
I tried:
after_save :clean_balance_cache

clean_balance_cache holds the expire_action method. But then I get an
error:
undefined method `expire_action’ for #Declaration:0xb69d19b0

Is there a way to make this work? Or should I make it work another way?

Thanks in advance!

I don’t know if it’s possible (you might be able to use ‘include
ActionController::Caching::Actions’ in the model) but I prefer my
cache expiration to be outside of the model and in sweeper files…

class DeclarationSweeper < ActionController::Caching::Sweeper

observe Declaration

def after_create(page)
# expire something…
end

end

idleFingers wrote:

I don’t know if it’s possible (you might be able to use ‘include
ActionController::Caching::Actions’ in the model) but I prefer my
cache expiration to be outside of the model and in sweeper files…

class DeclarationSweeper < ActionController::Caching::Sweeper

observe Declaration

def after_create(page)
# expire something…
end

end

Thanks. But the cache I want to sweep is based on the data of two
different models. Is it possible to call the same method
(clean_balance_cache) in two different sweeper files? The method
consists of `expire_action’ and some other things.

Leon B. wrote:

idleFingers wrote:

I don’t know if it’s possible (you might be able to use ‘include
ActionController::Caching::Actions’ in the model) but I prefer my
cache expiration to be outside of the model and in sweeper files…

class DeclarationSweeper < ActionController::Caching::Sweeper

observe Declaration

def after_create(page)
# expire something…
end

end

Thanks. But the cache I want to sweep is based on the data of two
different models. Is it possible to call the same method
(clean_balance_cache) in two different sweeper files? The method
consists of `expire_action’ and some other things.

This worked:

class BalanceSweeper < ActionController::Caching::Sweeper

observe Declaration, Deposit

def after_create(data)
clean_balance_cache
end

def after_save(data)
clean_balance_cache
end

def after_destroy(data)
end

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

end

Thanks!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs