views:

133

answers:

1

I have an app that hosts several accounts, each mapped to its own domain.

I want to define different page caching directories for each account.

I have this in my application controller (before filter):

self.page_cache_directory = RAILS_ROOT+"/public/cache/" + @account.name

But that doesn't seem right because it effectively overwrites the page_cache_directory variable for ActionController::Base (it is a cattr_accessor), being a problem with concurrent requests.

Is there a better way?

+2  A: 

Try in your app controller:

def the_before_filter
  @account = Account.find(...)
  (class << self; self; end).instance_eval { define_method :cache_page do |content, path|
     super content, @account.name + path
  end
  }
end

resources:

http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html

http://blog.jayfields.com/2007/10/ruby-defining-class-methods.html

MatthewFord
That shouldn't work, should it?: it's a class method but @account is an instance variable.
ismaSan
touché, lets try again..
MatthewFord