title: Rails Display Bootstrap Alerts Using Helpers
body: <p>I am trying to follow this Gist to display Bootstrap alerts for a crud rails app <a href="https://gist.github.com/suryart/7418454" rel="nofollow noreferrer">https://gist.github.com/suryart/7418454</a>. The contents of which have the code:</p>
  
  <p>application_helper.rb:</p>
  
  <p>module ApplicationHelper</p>
  
  <pre><code>  def bootstrap_class_for flash_type
      { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s
    end
  
    def flash_messages(opts = {})
      flash.each do |msg_type, message|
        concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do 
                concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' })
                concat message 
              end)
      end
      nil
    end
  </code></pre>
  
  <p>application.html.erb</p>
  
  <pre><code>&lt;body&gt;
      &lt;div class="container"&gt;
  
        &lt;%= flash_messages %&gt;
  
        &lt;%= yield %&gt;
      &lt;/div&gt;&lt;!-- /container --&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Problem is I am not seeing any of the messages displayed.</p>
  
  <p>I thought that maybe since the gist is showing to return nil that maybe I need to return the contents of the .each iterator so I did something like this in my helper to return the html:</p>
  
  <pre><code>  def flash_messages
      @flash_msg = ""
      flash.each do |msg_type, message|
        @flash_msg = concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do
                      concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' })
                      concat message
                    end)
        puts "@flash_msg: #{@flash_msg}"
      end
      @flash_msg
    end
  </code></pre>
  
  <p>But when you look at the output of the print statement it is showing me the enter HTML for the page, the end of which is actually the html I need:</p>
  
  <pre><code>&lt;div class="alert alert-info fade in"&gt;&lt;button class="close" data-dismiss="alert"&gt;x&lt;/button&gt;Signed in successfully.&lt;/div&gt;
  </code></pre>
  
  <p>How do I get this to work so that it only returns that last part and not the entire page?</p>