aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorAna María Martínez Gómez <ammartinez@suse.de>2018-08-08 10:35:03 +0200
committerAna María Martínez Gómez <ammartinez@suse.de>2018-08-08 11:47:11 +0200
commit4ca9fa11f9a9b5604371f260515c28a0f29cd921 (patch)
tree3e990e56c6a40383b77bfc967e0e11aa1facc8c4 /actionview
parent0c62e141a3fc9b2d00935bb99d2d5f465e1a4fb4 (diff)
downloadrails-4ca9fa11f9a9b5604371f260515c28a0f29cd921.tar.gz
rails-4ca9fa11f9a9b5604371f260515c28a0f29cd921.tar.bz2
rails-4ca9fa11f9a9b5604371f260515c28a0f29cd921.zip
Deprecate use of private methods in view's helpers
Instead of dropping it completely in case someone is relying (probably inadvertenly) on it.
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md4
-rw-r--r--actionview/lib/action_view/helpers/form_options_helper.rb14
2 files changed, 14 insertions, 4 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index 9fc120acbc..4c552c635a 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,7 +1,7 @@
-* Stop exposing public methods in view's helpers.
+* Deprecate exposing public methods in view's helpers.
For example, in methods like `options_from_collection_for_select`
- and `collection_select` it was possible to call private methods from
+ and `collection_select` it is possible to call private methods from
the objects used.
See [#33546](https://github.com/rails/rails/issues/33546) for details.
diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb
index 0fd68b66d4..2ecba2e337 100644
--- a/actionview/lib/action_view/helpers/form_options_helper.rb
+++ b/actionview/lib/action_view/helpers/form_options_helper.rb
@@ -794,7 +794,7 @@ module ActionView
def extract_values_from_collection(collection, value_method, selected)
if selected.is_a?(Proc)
collection.map do |element|
- element.public_send(value_method) if selected.call(element)
+ public_or_deprecated_send(element, value_method) if selected.call(element)
end.compact
else
selected
@@ -802,7 +802,17 @@ module ActionView
end
def value_for_collection(item, value)
- value.respond_to?(:call) ? value.call(item) : item.public_send(value)
+ value.respond_to?(:call) ? value.call(item) : public_or_deprecated_send(item, value)
+ end
+
+ def public_or_deprecated_send(item, value)
+ begin
+ item.public_send(value)
+ rescue NoMethodError
+ raise unless item.respond_to?(value, true) && !item.respond_to?(value)
+ ActiveSupport::Deprecation.warn "Using private methods in view's helpers is deprecated"
+ item.send(value)
+ end
end
def prompt_text(prompt)