Search code examples
ruby-on-rails-3formtastic

Add message to formtastic semantic error block


If there are semantic errors in the form (mostly from external API), I'd like to add an explanatory message, like so:

<%= semantic_form_for @order, :url => checkout_purchase_url, :html => {:class => 'payment'}, :wrapper_html => { :class => "field" }  do |f| %>
<% if f.has_errors? %>
    <p>There were errors that prevented your order from being submitted.  If you need assistance, please contact us toll-free at <strong>1-800-555-5555</strong>.</p>
    <%= f.semantic_errors %>
<% end %>
<% end %>

However, has_errors? is a protected method. Is there a way that I can do this? Thanks.


Solution

  • Not as hard as I thought. I fixed it by checking for errors on the object instead of the form:

    <% if @object.errors.any? %>
        <p>There were errors that prevented your order from being submitted.  If you need assistance, please contact us toll-free at <strong>1-800-555-5555</strong>.</p>
        <%= f.semantic_errors %>
    <% end %>
    

    Thanks for those who viewed.