diff options
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/base.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/url_for.rb | 21 | ||||
-rw-r--r-- | actionpack/lib/action_controller/railtie.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/url_rewriter.rb | 21 |
5 files changed, 45 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 0777d9dc16..f8ddc8da09 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -9,7 +9,7 @@ module ActionController include ActionController::Helpers include ActionController::HideActions - # include ActionController::UrlFor + include ActionController::UrlFor include ActionController::Redirecting include ActionController::Rendering include ActionController::Renderers::All @@ -82,12 +82,5 @@ module ActionController filter end - protected - - # Overwrite url rewriter to use request. - def _url_rewriter - return ActionController::UrlRewriter unless request - @_url_rewriter ||= ActionController::UrlRewriter.new(request, params) - end end end diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb new file mode 100644 index 0000000000..013834ddee --- /dev/null +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -0,0 +1,21 @@ +module ActionController + module UrlFor + extend ActiveSupport::Concern + + include ActionDispatch::Routing::UrlFor + include ActionController::RackDelegation + + def merge_options(options) + super.reverse_merge( + :host => request.host_with_port, + :protocol => request.protocol, + :_path_segments => request.symbolized_path_parameters + ) + end + + def _router + raise "In order to use #url_for, you must include the helpers of a particular " \ + "router. For instance, `include Rails.application.router.named_url_helpers" + end + end +end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 015a8212c4..5a16d82e49 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -1,6 +1,7 @@ require "action_controller" require "rails" require "action_view/railtie" +require "active_support/core_ext/class/subclasses" module ActionController class Railtie < Rails::Railtie diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 5f8bc6f325..0fa2a8b90c 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -336,7 +336,7 @@ module ActionController private def build_request_uri(action, parameters) unless @request.env['REQUEST_URI'] - options = @controller.__send__(:rewrite_options, parameters) + options = @controller.__send__(:merge_options, parameters) options.update(:only_path => true, :action => action) url = ActionController::UrlRewriter.new(@request, parameters) diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 272465d4f5..807b21cd0e 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -26,8 +26,14 @@ module ActionController # ROUTES TODO: Class method code smell def self.rewrite(router, options, path_segments=nil) + handle_positional_args(options) + rewritten_url = "" + # ROUTES TODO: Fix the tests + segments = options.delete(:_path_segments) + path_segments = path_segments ? path_segments.merge(segments || {}) : segments + unless options[:only_path] rewritten_url << (options[:protocol] || "http") rewritten_url << "://" unless rewritten_url.match("://") @@ -52,6 +58,21 @@ module ActionController protected + def self.handle_positional_args(options) + return unless args = options.delete(:_positional_args) + + keys = options.delete(:_positional_keys) + keys -= options.keys if args.size < keys.size - 1 # take format into account + + args = args.zip(keys).inject({}) do |h, (v, k)| + h[k] = v + h + end + + # Tell url_for to skip default_url_options + options.merge!(args) + end + def self.rewrite_authentication(options) if options[:user] && options[:password] "#{Rack::Utils.escape(options.delete(:user))}:#{Rack::Utils.escape(options.delete(:password))}@" |