Sha256: 323c33f9846cf66fa425f3a39d106857662f6e81233b572698f7ae76b5c039f3

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module EacRailsUtils
  module CommonFormHelper
    class FormBuilder
      module RadioSelectField
        def radio_select_field(field_name, radios_values, options = {})
          field(field_name, options) do
            radios(field_name, radios_values)
          end
        end

        private

        def radios(field_name, radios_values)
          b = ActiveSupport::SafeBuffer.new
          radios_values.each do |r|
            b << radio(field_name, r[0], r[1])
          end
          b
        end

        def radio(field_name, value, label)
          helper.content_tag(:div, class: 'radio') do
            helper.content_tag(:label) do
              form.radio_button(field_name, value) << label
            end
          end
        end

        def extract_select_options(options)
          options.extract!(:prompt, :include_blank)
        end

        def extract_association_key(field_name, options, key, method)
          return options.delete(key) if options.key?(key)
          if model_instance.class.respond_to?(:reflect_on_association)
            return model_instance.class.reflect_on_association(field_name).send(method)
          end

          raise "#{model_instance.class} não possui um método \"reflect_on_association\". " \
                "Defina explicitamente a opção :#{key}"
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
eac_rails_utils-0.25.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.24.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.23.4 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.23.3 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.23.2 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.23.1 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.23.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.22.3 app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb