Remove ActionView::Helpers::Tags::Base#value Monkey Patch #1485
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This library provides an override of
ActionView::Helpers::Tags::Base#value
(the method that is used to determine the current value of a form field built from a template object) that allows calling private methods. The implementation is otherwise the same as the one provide by ActionView.I ran into some bizarre edge cases with this implementation when using
OpenStruct
, for example just having theransack
gem in memory and then using af.text_field :test
with anOpenStruct
asmodel
will display a confusingwrong number of arguments, given 0 expected 2..3
message because#test
is a private method onKernel
. Regardless of how I got here, I don't think this monkey patch is necessary or desired anymore.Without looking in detail, the reason I believe this patch was created in the first place is because here we define a select tag with
:p
, and like:test
,:p
is a private method onKernel
, and creating a select tag in this way will cause the form builder to see if there is a:p
method to fetch an existing value.In the second commit in this PR, we can simply default
selected: nil
inoptions
such that the form builder does not try to figure out what the existing value is to see if one of the values is selected.I don't use Ransack directly much (outside of ActiveAdmin) so I can't say if that will be a breaking change, but the tests do pass after that change. Open to feedback!