Created
January 23, 2016 20:19
-
-
Save carlweis/995658b8b4e52b48258a to your computer and use it in GitHub Desktop.
Rails Twitter Boostrap form helper.
This file contains hidden or 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
module FormHelper | |
def errors_for(form, field) | |
content_tag(:p, form.object.errors[field].try(:first), class: 'help-block') | |
end | |
def form_group_for(form, field, &block) | |
has_errors = form.object.errors[field].present? | |
content_tag :div, class: "form-group #{'has-error' if has_errors}" do | |
concat form.label(field, class: 'control-label') | |
concat capture(&block) | |
concat errors_for(form, field) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment