From d3dd3847bc2633ecead36f602bfca21c9362b502 Mon Sep 17 00:00:00 2001 From: Maxime Garcia Date: Sat, 12 Dec 2015 11:22:08 +0100 Subject: Don't catch all NameError to reraise as ActionController::RoutingError #22368 --- actionpack/lib/action_dispatch/routing/route_set.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index c4228df925..2bd2e53252 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -30,9 +30,9 @@ module ActionDispatch controller = controller req res = controller.make_response! req dispatch(controller, params[:action], req, res) - rescue NameError => e + rescue ActionController::RoutingError if @raise_on_name_error - raise ActionController::RoutingError, e.message, e.backtrace + raise else return [404, {'X-Cascade' => 'pass'}, []] end @@ -42,6 +42,8 @@ module ActionDispatch def controller(req) req.controller_class + rescue NameError => e + raise ActionController::RoutingError, e.message, e.backtrace end def dispatch(controller, action, req, res) -- cgit v1.2.3 From 6d4aef984c0cd74ebd92b8d18a8e68f371fbb944 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 14 Dec 2015 09:52:52 -0500 Subject: Make Parameters#to_h and #to_unsafe_h return HWIA This makes these two methods to be more inline with the previous behavior of Parameters as Parameters used to be inherited from HWIA. Fixes #21391 --- actionpack/lib/action_controller/metal/strong_parameters.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 8af94551cf..8bc3c271e2 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -162,8 +162,8 @@ module ActionController end end - # Returns a safe +Hash+ representation of this parameter with all - # unpermitted keys removed. + # Returns a safe ActiveSupport::HashWithIndifferentAccess + # representation of this parameter with all unpermitted keys removed. # # params = ActionController::Parameters.new({ # name: 'Senjougahara Hitagi', @@ -175,15 +175,17 @@ module ActionController # safe_params.to_h # => {"name"=>"Senjougahara Hitagi"} def to_h if permitted? - @parameters.to_h + @parameters.deep_dup else slice(*self.class.always_permitted_parameters).permit!.to_h end end - # Returns an unsafe, unfiltered +Hash+ representation of this parameter. + # Returns an unsafe, unfiltered + # ActiveSupport::HashWithIndifferentAccess representation of this + # parameter. def to_unsafe_h - @parameters.to_h + @parameters.deep_dup end alias_method :to_unsafe_hash, :to_unsafe_h -- cgit v1.2.3 From 1a404abc03d5c3a731ba826d63fde149bc7c1d30 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 14 Dec 2015 17:57:39 -0600 Subject: Remove ActionView::Helpers::CacheHelper#fragment_cache_key Introduced in e56c63542780fe2fb804636a875f95cae08ab3f4, `CacheHelper#fragment_cache_key` is a duplicate of `ActionController::Caching::Fragments#fragment_cache_key`. We now require the view to provide this method on its own (as with `view_cache_dependencies`); `ActionController::Caching::Fragments` exports its version as a `helper_method`. --- actionpack/lib/action_controller/caching/fragments.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb index 2694d4c12f..4e141659ee 100644 --- a/actionpack/lib/action_controller/caching/fragments.rb +++ b/actionpack/lib/action_controller/caching/fragments.rb @@ -14,6 +14,12 @@ module ActionController # # expire_fragment('name_of_cache') module Fragments + extend ActiveSupport::Concern + + included do + helper_method :fragment_cache_key if respond_to?(:helper_method) + end + # Given a key (as described in +expire_fragment+), returns # a key suitable for use in reading, writing, or expiring a # cached fragment. All keys are prefixed with views/ and uses -- cgit v1.2.3 From 99caf9ae7e46d15a713d821fa8cd516a4d254446 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 14 Dec 2015 19:53:43 -0600 Subject: Add fragment_cache_key macro for controller-wide fragment cache key prefixes --- .../lib/action_controller/caching/fragments.rb | 45 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb index 4e141659ee..c42384b741 100644 --- a/actionpack/lib/action_controller/caching/fragments.rb +++ b/actionpack/lib/action_controller/caching/fragments.rb @@ -17,15 +17,54 @@ module ActionController extend ActiveSupport::Concern included do + if respond_to?(:class_attribute) + class_attribute :fragment_cache_keys + else + mattr_writer :fragment_cache_keys + end + + self.fragment_cache_keys = [] + helper_method :fragment_cache_key if respond_to?(:helper_method) end + module ClassMethods + # Allows you to specify controller-wide key prefixes for + # cache fragments. Pass either a constant +value+, or a block + # which computes a value each time a cache key is generated. + # + # For example, you may want to prefix all fragment cache keys + # with a global version identifier, so you can easily + # invalidate all caches. + # + # class ApplicationController + # fragment_cache_key "v1" + # end + # + # When it's time to invalidate all fragments, simply change + # the string constant. Or, progressively roll out the cache + # invalidation using a computed value: + # + # class ApplicationController + # fragment_cache_key do + # @account.id.odd? ? "v1" : "v2" + # end + # end + def fragment_cache_key(value = nil, &key) + self.fragment_cache_keys += [key || ->{ value }] + end + end + # Given a key (as described in +expire_fragment+), returns # a key suitable for use in reading, writing, or expiring a - # cached fragment. All keys are prefixed with views/ and uses - # ActiveSupport::Cache.expand_cache_key for the expansion. + # cached fragment. All keys begin with views/, + # followed by any controller-wide key prefix values, ending + # with the specified +key+ value. The key is expanded using + # ActiveSupport::Cache.expand_cache_key. def fragment_cache_key(key) - ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views) + head = self.class.fragment_cache_keys.map { |key| instance_exec(&key) } + tail = key.is_a?(Hash) ? url_for(key).split("://").last : key + ActiveSupport::Cache.expand_cache_key([*head, *tail], :views) end # Writes +content+ to the location signified by -- cgit v1.2.3