Sha256: a44482f1c721935c8442cc76899284f182bccb6d8b8b212ed1584d46dc409273
Contents?: true
Size: 1.1 KB
Versions: 17
Compression:
Stored size: 1.1 KB
Contents
module Eac module CommonFormHelper def common_form(model_instance, options = {}, &block) submit_label = options.delete(:submit_label) options[:html] ||= {} options[:html][:class] = 'CommonFormHelper' form_for(model_instance, options) do |form| fb = FormBuilder.new(form, self) errors(model_instance) << capture(fb, &block) << errors_not_showed(model_instance, fb.field_errors_showed) << form.submit(submit_label, class: 'btn btn-primary') end end private def errors(model_instance) if model_instance.errors.any? content_tag(:div, class: 'alert alert-danger', id: 'flash_alert') do 'Há pendências no preenchimento do formulário.' end else ActiveSupport::SafeBuffer.new end end def errors_not_showed(model_instance, field_errors_showed) s = ActiveSupport::SafeBuffer.new model_instance.errors.each do |k, v| next if field_errors_showed.include?(k) s << content_tag(:div, "#{k}: #{v}", class: 'error') end s end end end
Version data entries
17 entries across 17 versions & 1 rubygems