diff options
Diffstat (limited to 'actionpack/lib/action_controller/url_rewriter.rb')
-rw-r--r-- | actionpack/lib/action_controller/url_rewriter.rb | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 3451e6acc9..3364262e4c 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -1,10 +1,9 @@ module ActionController # Rewrites URLs for Base.redirect_to and Base.url_for in the controller. class UrlRewriter #:nodoc: - VALID_OPTIONS = [:action, :action_prefix, :action_suffix, :application_prefix, :module, :controller, :controller_prefix, :anchor, :params, :path_params, :id, :only_path, :overwrite_params, :host, :protocol ] - - def initialize(request, controller, action) - @request, @controller, @action = request, controller, action + RESERVED_OPTIONS = [:anchor, :params, :path_params, :only_path, :host, :protocol] + def initialize(request, parameters) + @request, @parameters = request, parameters @rewritten_path = @request.path ? @request.path.dup : "" end @@ -22,7 +21,7 @@ module ActionController end def to_str - "#{@request.protocol}, #{@request.host_with_port}, #{@request.path}, #{@controller}, #{@action}, #{@request.parameters.inspect}" + "#{@request.protocol}, #{@request.host_with_port}, #{@request.path}, #{@parameters[:controller]}, #{@parameters[:action]}, #{@request.parameters.inspect}" end private @@ -48,12 +47,14 @@ module ActionController return rewritten_url end - def rewrite_path(path, options) - include_id_in_path_params(options) - - path = rewrite_action(path, options) if options[:action] || options[:action_prefix] - path = rewrite_path_params(path, options) if options[:path_params] - path = rewrite_controller(path, options) if options[:controller] || options[:controller_prefix] + def rewrite_path(options) + options = options.symbolize_keys + RESERVED_OPTIONS.each {|k| options.delete k} + + path, extras = Routing::Routes.generate(options, @request) + path = "/#{path.join('/')}" + path += build_query_string(extras) + return path end |