I have a form with several fields that are associated with the same object_name :result. I have some jquery/javascript that hides all but one of these fields depending on a field that is chosen earlier in the form. How can I ensure that when I hit the submit button, the :result object is given the correct value, depending on which field is actually shown? It seems that since all the other fields are just hidden, rails gets confused as to which :result should be used.
<div class="Collection1 desc">
<div id="pf" class="result" style="display: none;">
<%= f.label :result %>
<%= f.radio_button :result, 'pass' %> Pass
<%= f.radio_button :result, 'fail' %> Fail
<br><br>
</div>
<div id="int" class ="result" style="display: none;">
<%= f.label :result %>
<%= f.number_field :result %>
</div>
<div id="text" class ="result" style="display: none;">
<%= f.label :result %>
<%= f.text_field :result %>
</div>
<div id="area" class ="result" style="display: none;">
<%= f.label :result %>
<%= f.text_area :result %>
</div>
</div>
You should also disable the fields that you are hiding. This way they will not get submitted with the form.