method
field_name
v8.0.0 -
Show latest stable
- Class:
ActionView::Helpers::FormBuilder
field_name(method, *methods, multiple: false, index: @options[:index])public
Generate an HTML name attribute value for the given name and field combination
Return the value generated by the FormBuilder for the given attribute name.
<%= form_with model: @article do |f| %> <%= f.text_field :title, name: f.field_name(:title, :subtitle) %> <%# => <input type="text" name="article[title][subtitle]"> %> <% end %> <%= form_with model: @article do |f| %> <%= f.text_field :tag, name: f.field_name(:tag, multiple: true) %> <%# => <input type="text" name="article[tag][]"> %> <% end %>