actionview/lib/action_view/helpers/form_tag_helper.rb
# Generate an HTML <tt>name</tt> attribute value for the given name and
# field combination
#
# Return the value generated by the <tt>FormBuilder</tt> for the given
# attribute name.
#
#   <%= text_field_tag :post, :title, name: field_name(:post, :title, :subtitle) %>
#   <%# => <input type="text" name="post[title][subtitle]">
#
#   <%= text_field_tag :post, :tag, name: field_name(:post, :tag, multiple: true) %>
#   <%# => <input type="text" name="post[tag][]">
#
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.




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 .
def field_name(object_name, method_name, *method_names, multiple: false, index: nil)
        names = method_names.map! { |name| "[#{name}]" }.join
        case
        when object_name.empty?
          "#{method_name}#{names}#{multiple ? "[]" : ""}"
        when index
          "#{object_name}[#{index}][#{method_name}]#{names}#{multiple ? "[]" : ""}"
        else
          "#{object_name}[#{method_name}]#{names}#{multiple ? "[]" : ""}"
        end
      end
def field_name ( object_name , method_name , * method_names , multiple : false , index : nil ) names = method_names . map! { | name | "[#{name}]" } . join case when object_name . empty? "#{method_name}#{names}#{multiple ? "[]" : ""}" when index "#{object_name}[#{index}][#{method_name}]#{names}#{multiple ? "[]" : ""}" else "#{object_name}[#{method_name}]#{names}#{multiple ? "[]" : ""}" end end
Generate an HTML <tt>name</tt> attribute value for the given name and
field combination
Generate an HTML <tt > name< / tt > attribute value for the given name and field combination
# a little duplication to construct fewer strings
object_name
<not_specific>
method_name
<not_specific>
method_names
<not_specific>
multiple
<not_specific>
index
<not_specific>