Sha256: 383a2d64155ee516341616aded9a75ef99392f5580d5000dab2bfd48c38dd01b

Contents?: true

Size: 811 Bytes

Versions: 4

Compression:

Stored size: 811 Bytes

Contents

# frozen_string_literal: true

module Eac
  module CommonFormHelper
    class FormBuilder
      module SelectField
        def select_field(field_name, options = {})
          options = options.dup
          field(field_name, options) do
            form.select(field_name, select_options(field_name, options))
          end
        end

        private

        def select_options(field_name, options)
          options[:options] || listable_select_options(field_name) || raise('No options found')
        end

        def listable_select_options(field_name)
          return nil unless model_instance.class.respond_to?(:lists)
          return nil unless model_instance.class.lists.respond_to?(field_name)

          model_instance.class.lists.send(field_name).options
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eac_rails_utils-0.10.1 lib/eac/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.10.0 lib/eac/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.9.1 lib/eac/common_form_helper/form_builder/select_field.rb
eac_rails_utils-0.9.0 lib/eac/common_form_helper/form_builder/select_field.rb