public this repo is viewable by everyone
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add conditional options to caches_page method [#25 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Paul Horsfall (author)
22 days ago
josh (committer)
22 days ago
commit  14a40804a29a57ad05ca6bffbe1e5334089593a9
tree    80e2d5f38334327a70a368cc2e57fc8c2e8f7c1c
parent  3f8d3cd04ff0bd7cbf70c11d49a3dc009dfa98a0
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Add conditional options to caches_page method. [Paul Horsfall]
0
+
0
 * Move missing template logic to ActionView. [Pratik]
0
 
0
 * Introduce ActionView::InlineTemplate class. [Pratik]
...
78
79
80
 
 
 
 
 
 
 
 
81
82
83
84
 
 
85
86
87
...
78
79
80
81
82
83
84
85
86
87
88
89
90
 
 
91
92
93
94
95
0
@@ -78,10 +78,18 @@ module ActionController #:nodoc:
0
 
0
         # Caches the +actions+ using the page-caching approach that'll store the cache in a path within the page_cache_directory that
0
         # matches the triggering url.
0
+ #
0
+ # Usage:
0
+ #
0
+ # # cache the index action
0
+ # caches_page :index
0
+ #
0
+ # # cache the index action except for JSON requests
0
+ # caches_page :index, :if => Proc.new { |c| !c.request.format.json? }
0
         def caches_page(*actions)
0
           return unless perform_caching
0
- actions = actions.map(&:to_s)
0
- after_filter { |c| c.cache_page if actions.include?(c.action_name) }
0
+ options = actions.extract_options!
0
+ after_filter({:only => actions}.merge(options)) { |c| c.cache_page }
0
         end
0
 
0
         private
...
8
9
10
11
 
 
12
13
14
...
127
128
129
 
 
 
 
 
 
130
131
132
...
8
9
10
 
11
12
13
14
15
...
128
129
130
131
132
133
134
135
136
137
138
139
0
@@ -8,7 +8,8 @@ ActionController::Base.page_cache_directory = FILE_STORE_PATH
0
 ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
0
 
0
 class PageCachingTestController < ActionController::Base
0
- caches_page :ok, :no_content, :found, :not_found
0
+ caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
0
+ caches_page :found, :not_found
0
 
0
   def ok
0
     head :ok
0
@@ -127,6 +128,12 @@ class PageCachingTest < Test::Unit::TestCase
0
       end
0
     end
0
   end
0
+
0
+ def test_page_caching_conditional_options
0
+ @request.env['HTTP_ACCEPT'] = 'application/json'
0
+ get :ok
0
+ assert_page_not_cached :ok
0
+ end
0
 
0
   private
0
     def assert_page_cached(action, message = "#{action} should have been cached")

Comments

    No one has commented yet.