diff options
Diffstat (limited to 'actionpack/lib/action_controller/dispatcher.rb')
-rw-r--r-- | actionpack/lib/action_controller/dispatcher.rb | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index f892058f20..92576bdb2b 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -20,17 +20,9 @@ module ActionController # existing callback. Passing an identifier is a suggested practice if the # code adding a preparation block may be reloaded. def to_prepare(identifier = nil, &block) - @prepare_dispatch_callbacks ||= [] + @prepare_dispatch_callbacks ||= ActiveSupport::Callbacks::CallbackChain.new callback = ActiveSupport::Callbacks::Callback.new(:prepare_dispatch, block, :identifier => identifier) - - # Already registered: update the existing callback - # TODO: Ruby one liner for Array#find returning index - if identifier && callback_for_identifier = @prepare_dispatch_callbacks.find { |c| c.identifier == identifier } - index = @prepare_dispatch_callbacks.index(callback_for_identifier) - @prepare_dispatch_callbacks[index] = callback - else - @prepare_dispatch_callbacks.concat([callback]) - end + @prepare_dispatch_callbacks.replace_or_append_callback(callback) end # If the block raises, send status code as a last-ditch response. |