title: Displaying simple_form error messages in top <div>
body: <p>I have the following two _forms:</p>
  
  <p><strong>user form</strong></p>
  
  <pre><code>&lt;%= simple_form_for(@user, :url =&gt; @target) do |f| %&gt;
    &lt;% if @user.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@user.errors.count, "error") %&gt; prohibited this user from being saved:&lt;/h2&gt;
        &lt;ul&gt;
        &lt;% @user.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;%= f.input :email, :label =&gt; "User Email" %&gt;
    &lt;%= f.input :password, :label =&gt; "User Password" %&gt;
    &lt;%= f.input :first_name %&gt;
    &lt;%= f.input :last_name %&gt;
    &lt;%= f.button :submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>tenant form</strong></p>
  
  <pre><code>&lt;%= simple_form_for(@tenant, :url =&gt; @target) do |f| %&gt;
    &lt;% if @tenant.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@tenant.errors.count, "error") %&gt; prohibited this tenant from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @tenant.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;%= f.input :name, :label =&gt; 'Name', :required =&gt; true %&gt;
    &lt;%= f.input :billing_email, :label =&gt; 'Email', :required =&gt; true %&gt;
    &lt;%= f.input :country, :label =&gt; 'Country', :required =&gt; true %&gt;
    &lt;%= f.button :submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I have come across the following post from stackoverflow <a href="https://stackoverflow.com/questions/3873190/f-error-messages-in-rails-3-0">f.error_messages in Rails 3.0</a></p>
  
  <p>Here there is method so that error messages can be returned from the simple form by using f.error_messages but I have been unable to get this working as I am unsure whereabout this method should be saved. Anyone got any hints? The method is as follows:</p>
  
  <pre><code>class StandardBuilder &lt; ActionView::Helpers::FormBuilder
    def error_messages
      return unless object.respond_to?(:errors) &amp;&amp; object.errors.any?
  
      errors_list = ""
      errors_list &lt;&lt; @template.content_tag(:span, "There are errors!", :class =&gt; "title-error")
      errors_list &lt;&lt; object.errors.full_messages.map { |message| @template.content_tag(:li, message) }.join("\n")
  
      @template.content_tag(:ul, errors_list.html_safe, :class =&gt; "error-recap round-border")
    end
  end
  </code></pre>