Created
June 9, 2015 13:52
-
-
Save slaith/dfe0c9c128d58b5ba6a1 to your computer and use it in GitHub Desktop.
Generator template for Bootstrap _form with error display on each field
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_for(@<%= singular_table_name %>, html: { class: "form-horizontal", role: "form" }) do |f| | |
- if @<%= singular_table_name %>.errors.any? | |
.alert.alert-danger.alert-dismissable role="alert" | |
button.close type="button" data-dismiss="alert" | |
span aria-hidden="true" | |
| × | |
span.sr-only | |
| Close | |
h4= "#{pluralize(@<%= singular_table_name %>.errors.count,"error")} prohibited this <%= singular_table_name %> from being saved:" | |
ul | |
- @<%= singular_table_name %>.errors.full_messages.each do |msg| | |
li= msg | |
<%- attributes.each do |attribute| -%> | |
.form-group | |
= f.label :<%= attribute.name %>, class: "col-sm-2 control-label"+ ((@<%=singular_table_name%>.errors[:<%=attribute.name%>])? "has-error":"") | |
.col-sm-10 | |
= f.<%= attribute.field_type %> :<%= attribute.name %>, class: "form-control" | |
- if (@<%=singular_table_name%>.errors[:<%=attribute.name%>]) | |
ul.errors.list-unstyled | |
- @<%=singular_table_name%>.errors[:<%=attribute.name%>].each do |error| | |
li.error.text-danger =" <%= attribute.name.humanize %> #{error}" | |
<%- end -%> | |
.form-group | |
.col-sm-offset-2.col-sm-10 | |
= f.submit class: "btn btn-primary" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment