The easiest way in Ruby-on-Rails to create some simple hidden fields with known values โโand the same name in several non-model forms (form_remote_tag in my case, but I assume it doesn't matter)?
By โplain hidden fieldโ I mean one where the name is only one string ( field_name), and not part of the array ( field_name[]), so the value can simply be read from the params hash as params[:field_name], rather than params[:field_name][0].
I found that
<% form_remote_tag :url => {:action => "do_act"} do %>
<%= hidden_field :field_name, 0, :name => "field_name", :value => "foo" %>
<%= submit_tag "Submit" %>
<% end %>
creates an acceptable element ( <input id="field_name_0" name="field_name" type="hidden" value="foo" />), but if I omit the parameter :name, then the displayed field has a name field_name[0]. Lowering 0obviously causes a really strange behavior.
<%= hidden_field_tag :field_name, "foo" %> creates an acceptable element if there is only one such form, but generates HTML warnings (duplicate identifiers) if there are more.
Is there a way to do this (prohibiting helper definitions) in fewer arguments?
source
share