Go back to the main page

Better looking Rails errors with Bootstrap and Fontawesome

 

Not to shabby, eh?

<!-- Standard form_for with render a partial, which is the next snippet -->
<%= form_for(@template) do |f| %>
<%= render 'shared/error_message', model: @template %>
<div class="field">


<!-- app/views/shared/_error_message.html.erb -->
<% if model.errors.any? %>
<div id="error_explanation">
  <h2><i class="fa fa-flag fa-2x pull-left"></i> <%= pluralize(model.errors.count, "error") %> prohibited this template from being saved:</h2>
  <ul class="fa-ul">
  <% model.errors.full_messages.each do |message| %>
    <li><i class="fa-li fa fa-star"></i> <%= message %></li>
  <% end %>
  </ul>
</div>
<% end %>


<!-- Styling -->
#error_explanation {
  @extend .alert;
  @extend .alert-danger;
  width: 50%;
  h2 {
    margin-top: 10px;
    font-size: 16px;
  }
  ul {
    margin-top: 2em;
  }
}
  • Pushed on 12/31/2014 by Christian