Deprecate use of private methods in view's helpers

Instead of dropping it completely in case someone is relying (probably
inadvertenly) on it.
上级 0c62e141
* 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.
......
......@@ -794,7 +794,7 @@ def extract_selected_and_disabled(selected)
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 @@ def extract_values_from_collection(collection, value_method, selected)
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册