Files

35 lines
1.1 KiB
Ruby

class CustomFormBuilder < ActionView::Helpers::FormBuilder
def supplier_form_actions(options = {})
t = @template
elements = []
elements << submit(nil, class: 'form-action-submit')
plural_subject = object.class.name.underscore.pluralize.to_sym
elements << t.link_to(
t.content_tag(:span, nil, data: {t: 'helpers.links.cancel'}),
[:suppliers, plural_subject],
class: 'form-action-cancel'
)
t.content_tag(:div, elements.inject(&:+), class: 'form-actions')
end
def row(attribute, options={}, &block)
t = @template
classes = []
classes << 'form-row'
classes << attribute
classes << 'error' if object.errors[attribute].present?
t.content_tag(:div, t.capture(&block), class: classes)
end
def error_message(attribute, options={}, &block)
if errors = object.errors[attribute].presence
t = @template
classes = ['error-message']
classes << attribute
classes |= Array.wrap(options[:class])
t.content_tag(:span, options[:message] || errors.join(', '), class: classes)
end
end
end
ActionView::Base.default_form_builder = CustomFormBuilder