You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But then it raised a question that if using = is the problem then the label and text-field tags should also have been duplicated but that isn't the case. So I tried to debug the source code and added following
caller_locations(0..20).map do |call|
puts call.to_s
end
above values.each do |content, value| line in the block given to super(attributes) in following method:
So I found that it is the template's evaluate method duplicate invocation which is causing the behaviour. To be more sure about this conclusion of mine this time I printed the complete call-trace by changing
caller_locations(0..20).map do |call|
puts call.to_s
end
to following
caller_locations.map do |call|
puts call.to_s
end
and retaining = select(:language, options) in the view and I found following:
Can anybody please help me understand such behavior that how just replacing a - with = in the haml file is causing duplicate invocation of view's call method?
And another question which is puzzling me is when using = with label and text_field methods why the duplicate label and input type=text tags were not rendered and the duplication was observed only for select's option tags.
Thanks.
The text was updated successfully, but these errors were encountered:
cllns
changed the title
form_form - Duplicate option tags generated for select tag
form_for - Duplicate option tags generated for select tag
Oct 19, 2024
Ruby 3.1.2
Gemfile
Gemfile.lock
my_view.html.haml
In my view I have following code generating a form using
form_for
helper.When the page is rendered in the select tag generated I can seen duplicate options
Experimenting with the code I figured out that the problem is with the helper methods prefixed with
=
.Updating the view code in following manner the duplicate options problem is gone:
But then it raised a question that if using
=
is the problem then the label and text-field tags should also have been duplicated but that isn't the case. So I tried to debug the source code and added followingabove
values.each do |content, value|
line in the block given tosuper(attributes)
in following method:helpers/lib/hanami/helpers/form_helper/form_builder.rb
Lines 1299 to 1319 in b9e8cf0
and then refreshing the page I found following in the server logs:
Above was found when used
-
beforeselect(:language, options)
in the view.When used
=
beforeselect(:language, options)
in the view following was found:As can be seen in above case following duplicate calls can be seen:
So I found that it is the template's
evaluate
method duplicate invocation which is causing the behaviour. To be more sure about this conclusion of mine this time I printed the complete call-trace by changingto following
and retaining
= select(:language, options)
in the view and I found following:So looking at the complete trace now I see that it is duplicate view call execution which is invoking twice that block inside
select
method.Can anybody please help me understand such behavior that how just replacing a
-
with=
in the haml file is causing duplicate invocation of view's call method?And another question which is puzzling me is when using
=
withlabel
andtext_field
methods why the duplicatelabel
andinput type=text
tags were not rendered and the duplication was observed only forselect
'soption
tags.Thanks.
The text was updated successfully, but these errors were encountered: