From 5a02f0bccf55191c2cfbcc69bd8165df6d7a2012 Mon Sep 17 00:00:00 2001 From: Tom Lea Date: Sat, 1 Nov 2008 17:50:16 +0000 Subject: Cleaned up route optimisation guard condition generation code as it was getting a little messy. Add additional condition to handle the case where default_url_options is only defined in the controller, not the view. Signed-off-by: Michael Koziarski --- .../lib/action_controller/routing/optimisations.rb | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/routing/optimisations.rb b/actionpack/lib/action_controller/routing/optimisations.rb index 894d4109e4..0a87303bda 100644 --- a/actionpack/lib/action_controller/routing/optimisations.rb +++ b/actionpack/lib/action_controller/routing/optimisations.rb @@ -20,14 +20,20 @@ module ActionController class Optimiser attr_reader :route, :kind + GLOBAL_GUARD_CONDITIONS = [ + "(!defined?(default_url_options) || default_url_options.blank?)", + "(!defined?(controller.default_url_options) || controller.default_url_options.blank?)", + "defined?(request)", + "request" + ] def initialize(route, kind) @route = route @kind = kind end - def guard_condition - 'false' + def guard_conditions + ["false"] end def generation_code @@ -36,6 +42,7 @@ module ActionController def source_code if applicable? + guard_condition = (GLOBAL_GUARD_CONDITIONS + guard_conditions).join(" && ") "return #{generation_code} if #{guard_condition}\n" else "\n" @@ -57,14 +64,14 @@ module ActionController # return a string like "/people/#{@person.to_param}" # rather than triggering the expensive logic in +url_for+. class PositionalArguments < Optimiser - def guard_condition + def guard_conditions number_of_arguments = route.segment_keys.size # if they're using foo_url(:id=>2) it's one # argument, but we don't want to generate /foos/id2 if number_of_arguments == 1 - "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)" + ["args.size == 1", "!args.first.is_a?(Hash)"] else - "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{number_of_arguments}" + ["args.size == #{number_of_arguments}"] end end @@ -98,8 +105,13 @@ module ActionController # above, but it supports additional query parameters as the last # argument class PositionalArgumentsWithAdditionalParams < PositionalArguments - def guard_condition - "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)" + def guard_conditions + [ + "args.size == #{route.segment_keys.size + 1}", + "!args.last.has_key?(:anchor)", + "!args.last.has_key?(:port)", + "!args.last.has_key?(:host)" + ] end # This case uses almost the same code as positional arguments, -- cgit v1.2.3 From b047929c14f088d535eea460ddd8769f43cd4ae5 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 2 Nov 2008 04:02:40 +0530 Subject: Merge with docrails --- actionpack/lib/action_controller/base.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 74c04147fb..cf86c5eed0 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1062,6 +1062,9 @@ module ActionController #:nodoc: # When using redirect_to :back, if there is no referrer, # RedirectBackError will be raised. You may specify some fallback # behavior for this case by rescuing RedirectBackError. + # + # When using redirect_to an instance variable called + # @performed_redirect will be set to true. def redirect_to(options = {}, response_status = {}) #:doc: raise ActionControllerError.new("Cannot redirect to nil!") if options.nil? -- cgit v1.2.3 From 8a53e258e541ede706a30ece80d89b3097efb686 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sun, 2 Nov 2008 13:12:48 +0100 Subject: Backwards compatibility fixes for relative_url_root * Make the old deprecated relative_url_root still set the value as it's still used by mongrel * Set the default from the ENV value when the file is required, not at runtime. --- actionpack/lib/action_controller/base.rb | 7 ++----- actionpack/lib/action_controller/request.rb | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index cf86c5eed0..0cf74cd53e 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -364,11 +364,8 @@ module ActionController #:nodoc: # If you are deploying to a subdirectory, you will need to set # config.action_controller.relative_url_root # This defaults to ENV['RAILS_RELATIVE_URL_ROOT'] - cattr_writer :relative_url_root - - def self.relative_url_root - @@relative_url_root || ENV['RAILS_RELATIVE_URL_ROOT'] - end + cattr_accessor :relative_url_root + self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT'] # Holds the request object that's primarily used to get environment variables through access like # request.env["REQUEST_URI"]. diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 9f33cbc55f..a6d4abf029 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -9,10 +9,11 @@ module ActionController class AbstractRequest extend ActiveSupport::Memoizable - def self.relative_url_root=(*args) + def self.relative_url_root=(relative_url_root) ActiveSupport::Deprecation.warn( "ActionController::AbstractRequest.relative_url_root= has been renamed." + "You can now set it with config.action_controller.relative_url_root=", caller) + ActionController::base.relative_url_root=relative_url_root end HTTP_METHODS = %w(get head put post delete options) -- cgit v1.2.3 From be1beb1a2d2c32aeb907b34d9d451b7a853c924d Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 2 Nov 2008 18:36:14 +0530 Subject: Dont document internals --- actionpack/lib/action_controller/base.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 0cf74cd53e..087fdc35cd 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1059,9 +1059,6 @@ module ActionController #:nodoc: # When using redirect_to :back, if there is no referrer, # RedirectBackError will be raised. You may specify some fallback # behavior for this case by rescuing RedirectBackError. - # - # When using redirect_to an instance variable called - # @performed_redirect will be set to true. def redirect_to(options = {}, response_status = {}) #:doc: raise ActionControllerError.new("Cannot redirect to nil!") if options.nil? -- cgit v1.2.3 From 934f98e4cf7c43f8c632496b02ac99492d6b3de1 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 2 Nov 2008 23:19:44 +0530 Subject: Dont dup params twice when filter_parameters is present --- actionpack/lib/action_controller/base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 087fdc35cd..61f9f354c3 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1244,8 +1244,8 @@ module ActionController #:nodoc: end def log_processing_for_parameters - parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params - parameters = parameters.except(:controller, :action, :format) + parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params.dup + parameters = parameters.except!(:controller, :action, :format) logger.info " Parameters: #{parameters.inspect}" end -- cgit v1.2.3 From 18bf7b421d55c60029289edef1df409a58d021e4 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 2 Nov 2008 23:23:19 +0530 Subject: Remove unused debug_routes --- actionpack/lib/action_controller/base.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 61f9f354c3..b001b355dc 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -278,12 +278,6 @@ module ActionController #:nodoc: @@consider_all_requests_local = true cattr_accessor :consider_all_requests_local - # Enable or disable the collection of failure information for RoutingErrors. - # This information can be extremely useful when tweaking custom routes, but is - # pointless once routes have been tested and verified. - @@debug_routes = true - cattr_accessor :debug_routes - # Indicates whether to allow concurrent action processing. Your # controller actions and any other code they call must also behave well # when called from concurrent threads. Turned off by default. -- cgit v1.2.3