aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/dispatcher.rb110
2 files changed, 62 insertions, 50 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 8746017245..bd94159061 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that auto reloading would some times not work or would reload the models twice #475 [Tobias Luetke]
+
* Added rewrite rules to deal with caching to public/.htaccess
* Added the option to specify a controller name to "generate scaffold" and made the default controller name the plural form of the model.
diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb
index 7ae2affb45..81c1ed9cb3 100644
--- a/railties/lib/dispatcher.rb
+++ b/railties/lib/dispatcher.rb
@@ -24,60 +24,70 @@
require 'breakpoint'
class Dispatcher
- def self.dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
- Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)
-
- begin
- request = ActionController::CgiRequest.new(cgi, session_options)
- response = ActionController::CgiResponse.new(cgi)
-
- controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)
+
+ class <<self
+
+ def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
+ Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)
- require_dependency("application")
- require_dependency(controller_path(controller_name, module_name))
+ begin
+ request = ActionController::CgiRequest.new(cgi, session_options)
+ response = ActionController::CgiResponse.new(cgi)
+
+ controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)
- controller_class(controller_name).process(request, response).out
- rescue Object => exception
- ActionController::Base.process_with_exception(request, response, exception).out
- ensure
- if Dependencies.mechanism == :load
- ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
- Dependencies.reload rescue nil # Ignore out of order reloading errors for Controllers
- remove_class_hierarchy(controller_class(controller_name), ActionController::Base)
+ require_dependency("application")
+ require_dependency(controller_path(controller_name, module_name))
+
+ reload_application rescue nil # Ignore out of order reloading errors for Controllers
+
+ controller_class(controller_name).process(request, response).out
+ rescue Object => exception
+ ActionController::Base.process_with_exception(request, response, exception).out
+ ensure
+ remove_class_hierarchy(controller_class(controller_name), ActionController::Base) if Dependencies.mechanism == :load
+ Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
end
-
- Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
end
- end
-
- def self.controller_path(controller_name, module_name = nil)
- if module_name
- "#{module_name}/#{Inflector.underscore(controller_name)}_controller"
- else
- "#{Inflector.underscore(controller_name)}_controller"
- end
- end
-
- def self.controller_class(controller_name)
- Object.const_get(controller_class_name(controller_name))
- end
-
- def self.controller_class_name(controller_name)
- "#{Inflector.camelize(controller_name)}Controller"
- end
-
- def self.controller_name(parameters)
- parameters["controller"].gsub(/[^_a-zA-Z0-9]/, "").untaint
- end
-
- def self.module_name(parameters)
- parameters["module"].gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"]
- end
+
+ private
+
+ def reload_application
+ if Dependencies.mechanism == :load
+ ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
+ Dependencies.reload
+ end
+ end
- def self.remove_class_hierarchy(klass, until_superclass)
- while klass
- Object.send(:remove_const, "#{klass}".intern)
- klass = (klass.superclass unless until_superclass == klass.superclass)
- end
+ def controller_path(controller_name, module_name = nil)
+ if module_name
+ "#{module_name}/#{Inflector.underscore(controller_name)}_controller"
+ else
+ "#{Inflector.underscore(controller_name)}_controller"
+ end
+ end
+
+ def controller_class(controller_name)
+ Object.const_get(controller_class_name(controller_name))
+ end
+
+ def controller_class_name(controller_name)
+ "#{Inflector.camelize(controller_name)}Controller"
+ end
+
+ def controller_name(parameters)
+ parameters["controller"].gsub(/[^_a-zA-Z0-9]/, "").untaint
+ end
+
+ def module_name(parameters)
+ parameters["module"].gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"]
+ end
+
+ def remove_class_hierarchy(klass, until_superclass)
+ while klass
+ Object.send(:remove_const, "#{klass}".intern)
+ klass = (klass.superclass unless until_superclass == klass.superclass)
+ end
+ end
end
end \ No newline at end of file