Sha256: 8f25f35e49cf24c58e81e07f36de4536efe365098f4cce1f14dbf6fd4b61be25

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

# frozen_string_literal: true

module EacRailsUtils
  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

1 entries across 1 versions & 1 rubygems

Version Path
eac_rails_utils-0.11.0 app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb