Add form error code
This commit is contained in:
parent
9632b9221b
commit
638fb7a8b1
6 changed files with 32 additions and 19 deletions
|
@ -1,5 +1,3 @@
|
|||
//= require_tree .
|
||||
//= require_self
|
||||
//= require 'custom'
|
||||
@import 'bootstrap-sprockets';
|
||||
@import 'bootstrap';
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
12
app/views/application/_form_messages.html.erb
Normal file
12
app/views/application/_form_messages.html.erb
Normal 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 %>
|
|
@ -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 %>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<%= link_to 'Edit', edit_friendship_path(@friendship) %> |
|
||||
<%= link_to 'Back', friendships_path %>
|
||||
|
|
Loading…
Reference in a new issue