Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed that auto reloading would some times not work or would reload t…

…he models twice #475 [Tobias Luetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@408 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 6c1fe632a3c2d4e71ce8f9e877f57180990c1532 1 parent c755b29
@dhh dhh authored
Showing with 62 additions and 50 deletions.
  1. +2 −0  railties/CHANGELOG
  2. +60 −50 railties/lib/dispatcher.rb
View
2  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.
View
110 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
Please sign in to comment.
Something went wrong with that request. Please try again.