Last active
November 22, 2018 01:06
-
-
Save jean182/5e2e275e4d0fc03357ec7e4ebbd39390 to your computer and use it in GitHub Desktop.
Bootstrap alert partial for form validation haml and erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if object.errors.any? %> | |
<div class="alert alert-danger alert-dismissible fade show" id="error_explanation" role="alert"> | |
<h4> | |
<%= pluralize(object.errors.count, "error") %> | |
prohibited | |
this object from being saved: | |
</h4> | |
<ul> | |
<% object.errors.full_messages.each do |msg| %> | |
<li> | |
<%= msg %> | |
</li> | |
<% end %> | |
</ul> | |
<button aria-label="Close" class="close" data-dismiss="alert" type="button"> | |
<span aria-hidden="true">×</span> | |
</button> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- if object.errors.any? | |
#error_explanation.alert.alert-danger.alert-dismissible.fade.show{role: "alert"} | |
%h4 | |
= pluralize(object.errors.count, "error") | |
prohibited | |
this | |
= object.model_name | |
from being saved: | |
%ul | |
- object.errors.full_messages.each do |msg| | |
%li{ class: 'list-unstyled' }= msg | |
%button.close{"aria-label" => "Close", "data-dismiss" => "alert", type: "button"} | |
%span{"aria-hidden" => "true"} × |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_with(model: post, local: true) do |form| %> | |
<%= render 'shared/errors', object: @post %> | |
<div class="form-group"> | |
<%= form.label :title %> | |
<%= form.text_field :title, class: "form-control", placeholder: "Title" %> | |
</div> | |
<div class="form-group"> | |
<%= form.label :body %> | |
<%= form.text_area :body, class: "form-control", placeholder: "Insert your post here..." %> | |
</div> | |
<div class="actions"> | |
<%= form.submit "Send", class: "btn btn-info" %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= form_with(model: post, local: true) do |form| | |
= render 'shared/errors', object: @post | |
.form-group | |
= form.label :title | |
= form.text_field :title, class: "form-control", placeholder: "Title" | |
.form-group | |
= form.label :body | |
= form.text_area :body, class: "form-control", placeholder: "Insert your post here..." | |
.actions | |
= form.submit "Send", class: "btn btn-info" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment