On Feb 11, 11:14 am, "Levy Carneiro Jr." <[email protected]>
wrote:

> I tried this also:
>
> class ArchivesObserver < ActionController::Caching::Sweeper
> (...)
>
> In this case, there's no error, and it does nothing at all. The
> public/archives.html just stays there.
>
> I'm trying my best to avoid hacking it, using a simple File.delete :)
> Like the code below:
>
>     # File rails/actionpack/lib/action_controller/caching/pages.rb, line 65
> 65:         def expire_page(path)
> 66:           return unless perform_caching
> 67:
> 68:           benchmark "Expired page: #{page_cache_file(path)}" do
> 69:             File.delete(page_cache_path(path)) if
> File.exist?(page_cache_path(path))
> 70:           end
> 71:         end
>
> Is there a way to expire pages without having to hack it?

I ran into a similar issue a few days ago. If I remember correctly, if
you look at what Rails is doing under the covers, you'll see that
ActionController::Caching::Sweeper subclasses will only work when
called from inside a controller. Basically the "expire_page" message
ends up getting intercepted by "method_missing", which tries to
forward it on to a controller stored in the @controller instance
variable. So if you invoke your Sweeper subclass from somewhere else
(like a Rake task), that @controller variable will be nil and nothing
will happen.

My workaround was just to fall back to File.delete and friends. Ugly,
but it works.

Cheers,
Wincent
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to