aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/dispatch')
-rw-r--r--actionpack/lib/action_controller/dispatch/dispatcher.rb52
-rw-r--r--actionpack/lib/action_controller/dispatch/middlewares.rb14
-rw-r--r--actionpack/lib/action_controller/dispatch/rescue.rb16
3 files changed, 41 insertions, 41 deletions
diff --git a/actionpack/lib/action_controller/dispatch/dispatcher.rb b/actionpack/lib/action_controller/dispatch/dispatcher.rb
index e205245f13..74c72e1a8b 100644
--- a/actionpack/lib/action_controller/dispatch/dispatcher.rb
+++ b/actionpack/lib/action_controller/dispatch/dispatcher.rb
@@ -5,15 +5,14 @@ module ActionController
class << self
def define_dispatcher_callbacks(cache_classes)
unless cache_classes
- # Development mode callbacks
- before_dispatch :reload_application
- after_dispatch :cleanup_application
+ unless self.middleware.include?(Reloader)
+ self.middleware.insert_after(ActionDispatch::Failsafe, Reloader)
+ end
ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
end
if defined?(ActiveRecord)
- after_dispatch :checkin_connections
to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers }
end
@@ -42,6 +41,30 @@ module ActionController
callback = ActiveSupport::Callbacks::Callback.new(:prepare_dispatch, block, :identifier => identifier)
@prepare_dispatch_callbacks.replace_or_append!(callback)
end
+
+ def run_prepare_callbacks
+ if defined?(Rails) && Rails.logger
+ logger = Rails.logger
+ else
+ logger = Logger.new($stderr)
+ end
+
+ new(logger).send :run_callbacks, :prepare_dispatch
+ end
+
+ def reload_application
+ # Run prepare callbacks before every request in development mode
+ run_prepare_callbacks
+
+ Routing::Routes.reload
+ end
+
+ def cleanup_application
+ # Cleanup the application before processing the current request.
+ ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
+ ActiveSupport::Dependencies.clear
+ ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
+ end
end
cattr_accessor :middleware
@@ -88,29 +111,8 @@ module ActionController
dispatch
end
- def reload_application
- # Run prepare callbacks before every request in development mode
- run_callbacks :prepare_dispatch
-
- Routing::Routes.reload
- end
-
- # Cleanup the application by clearing out loaded classes so they can
- # be reloaded on the next request without restarting the server.
- def cleanup_application
- ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
- ActiveSupport::Dependencies.clear
- ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
- end
-
def flush_logger
Base.logger.flush
end
-
- def checkin_connections
- # Don't return connection (and peform implicit rollback) if this request is a part of integration test
- return if @env.key?("rack.test")
- ActiveRecord::Base.clear_active_connections!
- end
end
end
diff --git a/actionpack/lib/action_controller/dispatch/middlewares.rb b/actionpack/lib/action_controller/dispatch/middlewares.rb
index 3bf3dbebab..b62b4f84a1 100644
--- a/actionpack/lib/action_controller/dispatch/middlewares.rb
+++ b/actionpack/lib/action_controller/dispatch/middlewares.rb
@@ -4,18 +4,10 @@ use "Rack::Lock", :if => lambda {
use "ActionDispatch::Failsafe"
-["ActionDispatch::Session::CookieStore",
- "ActionDispatch::Session::MemCacheStore",
- "ActiveRecord::SessionStore"].each do |store|
- use(store, ActionController::Base.session_options,
- :if => lambda {
- if session_store = ActionController::Base.session_store
- session_store.name == store
- end
- }
- )
-end
+use lambda { ActionController::Base.session_store },
+ lambda { ActionController::Base.session_options }
use "ActionDispatch::RewindableInput"
use "ActionDispatch::ParamsParser"
use "Rack::MethodOverride"
+use "Rack::Head"
diff --git a/actionpack/lib/action_controller/dispatch/rescue.rb b/actionpack/lib/action_controller/dispatch/rescue.rb
index df0a976204..ec9eff65a9 100644
--- a/actionpack/lib/action_controller/dispatch/rescue.rb
+++ b/actionpack/lib/action_controller/dispatch/rescue.rb
@@ -99,13 +99,19 @@ module ActionController #:nodoc:
# Attempts to render a static error page based on the
# <tt>status_code</tt> thrown, or just return headers if no such file
- # exists. For example, if a 500 error is being handled Rails will first
- # attempt to render the file at <tt>public/500.html</tt>. If the file
- # doesn't exist, the body of the response will be left empty.
+ # exists. At first, it will try to render a localized static page.
+ # For example, if a 500 error is being handled Rails and locale is :da,
+ # it will first attempt to render the file at <tt>public/500.da.html</tt>
+ # then attempt to render <tt>public/500.html</tt>. If none of them exist,
+ # the body of the response will be left empty.
def render_optional_error_file(status_code)
status = interpret_status(status_code)
- path = "#{Rails.public_path}/#{status.to_s[0,3]}.html"
- if File.exist?(path)
+ locale_path = "#{Rails.public_path}/#{status[0,3]}.#{I18n.locale}.html" if I18n.locale
+ path = "#{Rails.public_path}/#{status[0,3]}.html"
+
+ if locale_path && File.exist?(locale_path)
+ render :file => locale_path, :status => status, :content_type => Mime::HTML
+ elsif File.exist?(path)
render :file => path, :status => status, :content_type => Mime::HTML
else
head status