17 lines
529 B
Ruby
17 lines
529 B
Ruby
|
module FormHelper
|
||
|
def errors_for(form, field)
|
||
|
pp form.object.errors[field].first
|
||
|
content_tag(:p, form.object.errors[field].try(:first), class: 'my-2 help-block')
|
||
|
end
|
||
|
|
||
|
def form_group_for(form, field, opts = {}, &block)
|
||
|
label = opts.fetch(:label, true)
|
||
|
has_errors = form.object.errors[field].present?
|
||
|
|
||
|
content_tag :div, class: "form-group col #{'alert alert-info' if has_errors}" do
|
||
|
concat form.label(field, class: 'control-label') if label
|
||
|
concat capture(&block)
|
||
|
concat errors_for(form, field)
|
||
|
end
|
||
|
end
|
||
|
end
|