diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2014-07-31 13:05:56 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2014-07-31 13:24:16 -0300 |
commit | 8d61463f34fd0bb7bad446f2d43aaa63fee61563 (patch) | |
tree | ddf53f4eb1b6633b289ce44768e734eefd4d8d19 /actionpack | |
parent | 84093c662770893ad840c36f2b99204593d4a7de (diff) | |
download | rails-8d61463f34fd0bb7bad446f2d43aaa63fee61563.tar.gz rails-8d61463f34fd0bb7bad446f2d43aaa63fee61563.tar.bz2 rails-8d61463f34fd0bb7bad446f2d43aaa63fee61563.zip |
Push options check up so we can simplify internal methods
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/url.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 473f692b05..32234d18ab 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -51,28 +51,25 @@ module ActionDispatch def path_for(options) result = options[:script_name].to_s.chomp("/") result << options[:path].to_s - result = add_trailing_slash(result) if options[:trailing_slash] - - result = add_params options, result - add_anchor options, result + result = add_params(result, options[:params]) if options.key?(:params) + result = add_anchor(result, options[:anchor]) if options.key?(:anchor) + result end private - def add_params(options, result) - if options.key? :params - param = options[:params] - params = param.is_a?(Hash) ? param : { params: param } + def add_params(result, param) + params = param.is_a?(Hash) ? param : { params: param } + + params.reject! { |_,v| v.to_param.nil? } + result << "?#{params.to_query}" unless params.empty? - params.reject! { |_,v| v.to_param.nil? } - result << "?#{params.to_query}" unless params.empty? - end result end - def add_anchor(options, result) - result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor] + def add_anchor(result, anchor) + result << "##{Journey::Router::Utils.escape_fragment(anchor.to_param.to_s)}" result end |