Skip to content

Instantly share code, notes, and snippets.

@carlweis
Created January 23, 2016 20:19
Show Gist options
  • Save carlweis/995658b8b4e52b48258a to your computer and use it in GitHub Desktop.
Save carlweis/995658b8b4e52b48258a to your computer and use it in GitHub Desktop.
Rails Twitter Boostrap form helper.
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