-------------------------------- NAME -------------------------------- rails_errors2html -------------------------------- DESCRIPTION -------------------------------- sane html rendering of active_model errors -------------------------------- SYNOPSIS -------------------------------- ````erb <%= form_for @post do %> <%= @post.errors %> <%= @post.errors.to_s %> <%= @post.errors.to_html %> <% end %> <%= Errors2Html.to_html(@post.errors, @comment.errors) %> ```` you can override the built-in template like so ````ruby # file : config/initializers/errors2html.rb Errors2Html.template = 'shared/errors' ```` here is an example template. note that errors are partioned into global and field based errors. ````erb

Sorry, we encountered some errors:

<% unless errors.global.empty? %> <% end %> <% unless errors.fields.empty? %>
<% errors.fields.each do |key, messages| title = Array(key).join(" ").titleize %>
<%= title %>
<% Array(messages).each do |message| %>
<%= message %>
<% end %> <% end %>
<% end %>
```` you might want some css like this ````css .errors-summary { box-sizing: border-box; width: 100%; height: auto; color: #333; background-color: #fffff6; padding: 1em; } .errors-caption { font-weight: bold; } .errors-title { } .errors-message { } ```` -------------------------------- INSTALL -------------------------------- gem install rails_errors2html gem 'rails_errors2html' bundle install