0

I want to cache an action and I want it to be different depending on a request param ('type').

How can I do that? I want that not only the rendering will be cached, but also the calculation and the DB requests (most of the action itself)

One possible solution would be to save the different results to a file and once created to redirect to a proxy actions for each type and render them, but that it overly complicated solution and maybe Rails has a better build-in solution.

Is it possible?

Thank you

4

1 回答 1

0

您可以使用 abefore filter检查参数类型并继续执行必要的操作。

before_filter :check_params, :only => :some_action
caches_action :some_action

def check_params
  if params["type"] == 'something'
    query_method1
  else
    query_method2
  end
end
于 2013-04-10T06:36:30.773 回答