aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG4
-rw-r--r--actionpack/lib/action_controller/caching.rb5
-rw-r--r--activerecord/lib/active_record/observer.rb10
3 files changed, 16 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 3fd9a7dba8..9001ffb7fb 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,9 @@
*SVN*
+* Allow sweepers to be created solely for expiring after controller actions, not model changes [DHH]
+
+* Added assigns method to ActionController::Caching::Sweeper to easily access instance variables on the controller [DHH]
+
* Give the legacy X-POST_DATA_FORMAT header greater precedence during params parsing for backward compatibility. [Jeremy Kemper]
* Fixed that link_to with an href of # when using :method will not allow for click-through without JavaScript #7037 [stevenbristol/josh]
diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb
index f9f3c37c1c..75aa9df812 100644
--- a/actionpack/lib/action_controller/caching.rb
+++ b/actionpack/lib/action_controller/caching.rb
@@ -636,6 +636,11 @@ module ActionController #:nodoc:
ActionController::Caching::Actions::ActionCachePath.path_for(controller, options)
end
+ # Retrieve instance variables set in the controller.
+ def assigns(key)
+ controller.instance_variable_get("@#{key}")
+ end
+
private
def callback(timing)
controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb
index ace52ef415..29edabc9b1 100644
--- a/activerecord/lib/active_record/observer.rb
+++ b/activerecord/lib/active_record/observer.rb
@@ -140,7 +140,11 @@ module ActiveRecord
# The class observed by default is inferred from the observer's class name:
# assert_equal [Person], PersonObserver.observed_class
def observed_class
- name.scan(/(.*)Observer/)[0][0].constantize
+ if observed_class_name = name.scan(/(.*)Observer/)[0]
+ observed_class_name[0].constantize
+ else
+ nil
+ end
end
end
@@ -163,11 +167,11 @@ module ActiveRecord
protected
def observed_classes
- Set.new([self.class.observed_class].flatten)
+ Set.new([self.class.observed_class].compact.flatten)
end
def observed_subclasses
- observed_classes.sum(&:subclasses)
+ observed_classes.collect(&:subclasses).flatten
end
def add_observer!(klass)