我有一个托管多个帐户的应用,每个帐户都映射到自己的域。
我想为每个帐户定义不同的页面缓存目录。
我在我的应用程序控制器(过滤器之前)中有这个:
self.page_cache_directory = RAILS_ROOT+"/public/cache/" + @account.name
但这似乎不正确,因为它有效地覆盖了ActionController :: Base的page_cache_directory变量(它是一个cattr_accessor),这是并发请求的问题。
有更好的方法吗?
答案 0 :(得分:2)
试试你的app控制器:
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
资源:
http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
http://blog.jayfields.com/2007/10/ruby-defining-class-methods.html