Sha256: f5d3d99ea1e9c3ceee3ef80ea8838828df0565b80aa8a648123794449e8ac75b

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

module Eac
  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
          fail "#{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

17 entries across 17 versions & 1 rubygems

Version Path
eac_rails_utils-0.8.0 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.7.1 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.7.0 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.6.0 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.5.0 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.4.0 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.3.0 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.2.2 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.2.1 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.2.0 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.1.15 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.1.14 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.1.13 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.1.12 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.1.11 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.1.10 lib/eac/common_form_helper/form_builder/radio_select_field.rb
eac_rails_utils-0.0.1 lib/eac/common_form_helper/form_builder/radio_select_field.rb