title: Rails 4: nested content_tag in methods and blocks
body: <p>I think I have created a bit of a nasty problem for myself. See below:</p>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;% tl = tablist_initialize(params[:tab], 'profile') %&gt;
  
  # lots of html
  # ...
  
  &lt;%= tl.tab_content do %&gt;
      &lt;% tl.tab_panel 'profile' do %&gt;
          Hello!
      &lt;% end %&gt;
      &lt;% tl.tab_panel 'settings' do %&gt;
        Sup!
      &lt;% end %&gt;
      &lt;% tl.tab_panel 'notifications' do %&gt;
        Nothing!
      &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>Helper</strong></p>
  
  <pre><code>class TabList
      include ActionView::Helpers::TagHelper
      include ActionView::Helpers::TextHelper
      attr_accessor :output_buffer
  
      def initialize(tab, primary)
        @current_tab = tab
        @primary = primary
      end
  
      def tab_content(&amp;block)
          content_tag(:div, :class =&gt; "tab-content", &amp;block)
      end
  
      def tab_panel(id, &amp;block)
          concat(content_tag(:div, {:class =&gt; (@current_tab == id ? "tab-pane active" : "tab-pane"),
            :role =&gt; "tabpanel", :id =&gt; id }, &amp;block))
      end
  
      # other methods
      # ...
  end
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <p>My plan here, is to create bootstrap tab easily. The result is now like this:</p>
  
  <pre><code>Hello! Sup! Nothing!
  &lt;div class="tab-content"&gt;
      &lt;div class="tab-pane active" role="tabpanel" id="profile"&gt;
           Hello!
      &lt;/div&gt;
      &lt;div class="tab-pane" role="tabpanel" id="settings"&gt;
          Sup!
      &lt;/div&gt;
      &lt;div class="tab-pane" role="tabpanel" id="notifications"&gt;    
          Nothing!
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Why the first line of the result (Hello! Sup! Nothing!)? I think it is strange that is outputs the inner block(s) two times: once right and once totally outside of either blocks (in the beginning). I tried different approaches: omitting the concat function, using concat around yield in the first content_tag, but all of these attempts did not give me the wished result.</p>