title: Rails Custom Form Builder. Custom text_field
body: <p>I am trying to create custom form builder in rails to convert this code </p>
  
  <pre><code>    &lt;div class="row collapse"&gt;
        &lt;div class="large-4 columns"&gt;
          &lt;%= builder.label :vacancy_title, "Title of the Vacancy", class: "right inline" %&gt;
        &lt;/div&gt;
        &lt;div class="large-8 columns"&gt;
          &lt;%= builder.text_field :vacancy_title, class: "tiny" %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>to simple </p>
  
  <pre><code>&lt;%= builder.t_field :vacancies, "Label title" %&gt;
  </code></pre>
  
  <p>I am trying this code with no luck, it just displays label.</p>
  
  <pre><code>#form_builders/custom_form_builder.rb
  class CustomFormBuilder &lt; ActionView::Helpers::FormBuilder
  def t_field(name, title, *args)
     @template.content_tag :div, class: "row collapse" do
       @template.content_tag :div, class: "large-8 columns" do
     text_field_tag(name, *args)
       end
  
     @template.content_tag :div, class: "large-4 columns" do
       @template.content_tag :h5 do
         label(title, options[:label], class: "right inline")
       end
     end
  
   end
  end
  </code></pre>
  
  <p>Something is obviously wrong with text_field_tag(name, *args), but I have no idea how to declare input. I couldn't found any docs on rubyapi Helpers::FormBuilder</p>
  
  <p><strong>SOLVED</strong></p>
  
  <p>Thanks to Levi Stanley i solved this with the following code. I need to change <code>text_field_tag(name, *args)</code> with <code>text_field_tag("#{object_name}[#{name}]")</code> and <code>label(title, options[:label], class: "right inline")</code> with <code>label(name, title, *args, class: "right")</code> in order the form works properly with nested attributes.</p>
  
  <pre><code>class LabeledFormBuilder &lt; ActionView::Helpers::FormBuilder
    def t_field(name, title, *args)
      @template.content_tag :div, class: "row collapse" do
        (@template.content_tag :div, class: "large-4 columns" do
          @template.content_tag :h5 do
            label(name, title, *args, class: "right")
          end
        end) +
        (@template.content_tag :div, class: "large-8 columns" do
          @template.text_field_tag("#{object_name}[#{name}]")
        end)
      end
    end
  end
  </code></pre>