1
0
Fork 0

Add form error code

This commit is contained in:
Andrew Tomaka 2014-10-15 13:56:55 -04:00
parent 9632b9221b
commit 638fb7a8b1
6 changed files with 32 additions and 19 deletions

View file

@ -1,5 +1,3 @@
//= require_tree .
//= require_self
//= require 'custom'
@import 'bootstrap-sprockets';
@import 'bootstrap';

View file

@ -1,3 +1,19 @@
@import 'bootstrap-sprockets';
@import 'bootstrap';
body {
padding-top: 70px;
}
#form-errors {
color: #f00;
ul {
list-style: none;
margin: 0 0 18px 0;
}
}
.field_with_errors {
@extend .form-group;
@extend .has-error;
}

View file

@ -0,0 +1,12 @@
<% if object.errors.any? %>
<div id="form-errors">
<div class="alert alert-danger">
The form contains <%= pluralize(object.errors.count, 'error') %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

View file

@ -1,17 +1,6 @@
<%= form_for(@friendship) do |f| %>
<% if @friendship.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@friendship.errors.count, "error") %> prohibited this friendship from being saved:</h2>
<ul>
<% @friendship.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
<%= form_for @friendship, html: { role: 'form' } do |f| %>
<%= render 'form_messages', object: @friendship %>
<div class="form-group">
<%= f.submit class: 'btn btn-primary' %>
</div>
<% end %>

View file

@ -11,7 +11,6 @@
<% @friendships.each do |friendship| %>
<tr>
<td><%= link_to 'Show', friendship %></td>
<td><%= link_to 'Edit', edit_friendship_path(friendship) %></td>
<td><%= link_to 'Destroy', friendship, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>

View file

@ -1,4 +1,3 @@
<p id="notice"><%= notice %></p>
<%= link_to 'Edit', edit_friendship_path(@friendship) %> |
<%= link_to 'Back', friendships_path %>