aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-10-28 09:43:33 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-10-28 09:43:33 -0700
commitaa1fadd48fb40dd9396a383696134a259aa59db9 (patch)
tree7cba2dfe0109b54cb66233af9fe68d58214ea7c9 /actionpack/lib
parent8607577fc8f2d5767d9fc8001b3985fa541aa557 (diff)
downloadrails-aa1fadd48fb40dd9396a383696134a259aa59db9.tar.gz
rails-aa1fadd48fb40dd9396a383696134a259aa59db9.tar.bz2
rails-aa1fadd48fb40dd9396a383696134a259aa59db9.zip
Deprecate the `only_path` option on `*_path` helpers.
In cases where this option is set to `true`, the option is redundant and can be safely removed; otherwise, the corresponding `*_url` helper should be used instead. Fixes #17294. See also #17363. [Dan Olson, Godfrey Chan]
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index f51bee3b31..8d4a3c5670 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -134,8 +134,8 @@ module ActionDispatch
@url_helpers_module.send :undef_method, url_name
end
routes[key] = route
- define_url_helper @path_helpers_module, route, path_name, route.defaults, name, PATH
- define_url_helper @url_helpers_module, route, url_name, route.defaults, name, FULL
+ define_url_helper @path_helpers_module, route, path_name, route.defaults, name, LEGACY
+ define_url_helper @url_helpers_module, route, url_name, route.defaults, name, UNKNOWN
@path_helpers << path_name
@url_helpers << url_name
@@ -322,6 +322,30 @@ module ActionDispatch
PATH = ->(options) { ActionDispatch::Http::URL.path_for(options) }
FULL = ->(options) { ActionDispatch::Http::URL.full_url_for(options) }
UNKNOWN = ->(options) { ActionDispatch::Http::URL.url_for(options) }
+ LEGACY = ->(options) {
+ if options.key?(:only_path)
+ if options[:only_path]
+ ActiveSupport::Deprecation.warn \
+ "You are calling a `*_path` helper with the `only_path` option " \
+ "expicitly set to `true`. This option will stop working on " \
+ "path helpers in Rails 5. Simply remove the `only_path: true` " \
+ "argument from your call as it is redundant when applied to a " \
+ "path helper."
+
+ PATH.call(options)
+ else
+ ActiveSupport::Deprecation.warn \
+ "You are calling a `*_path` helper with the `only_path` option " \
+ "expicitly set to `false`. This option will stop working on " \
+ "path helpers in Rails 5. Use the corresponding `*_url` helper " \
+ "instead."
+
+ FULL.call(options)
+ end
+ else
+ PATH.call(options)
+ end
+ }
# :startdoc:
attr_accessor :formatter, :set, :named_routes, :default_scope, :router