Sha256: 22b618999707441f1d162d7d44e717363edd1806c53fd03435807f3feb1db3d6
Contents?: true
Size: 1.43 KB
Versions: 41
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true module EacRailsUtils module CommonFormHelper class FormBuilder module FieldsFor def fields_for(association, &block) fieldset(association) do nested_fields(association, &block) << add_link(association) end end private def nested_fields(association, &block) form.nested_fields_for(association) do |nested_form| helper.content_tag(:div, class: 'nested_form_row') do helper.capture(FormBuilder.new(nested_form, helper), &block) << remove_link(nested_form) end end end def add_link(association) form.add_nested_fields_link(association, 'Adicionar', class: 'btn btn-primary', role: 'button') end def remove_link(nested_form) nested_form.remove_nested_fields_link('Remover', class: 'btn btn-danger', role: 'button') end def fieldset(association, &block) helper.content_tag(:fieldset, class: 'nested_form') do helper.content_tag(:legend, fieldset_legend(association)) << block.call end end def fieldset_legend(association) I18n.t("helpers.label.#{form.object.class.name.underscore}.#{association}") end end end end end
Version data entries
41 entries across 41 versions & 1 rubygems