Sha256: 0fc3ea37e9dd61c7da6ea44fb1db121e1e81b2c11bf60e7502fb7d2199007e11
Contents?: true
Size: 1.4 KB
Versions: 30
Compression:
Stored size: 1.4 KB
Contents
<!-- A `<select>` menu containing the values of an 'enum string'. ### Attributes - `labels` - A hash that gives custom labels for the values of the enum. This attribute is present for backwards compatibility. A better way to customize the labels is to use the translation framework. The key for enum 'e' on field 'f' for model 'm' would be `activerecord.attributes.m.f.e`. - `titleize` - Set to false to have the value itself (rather than `value.titleize`) be the default label if translation fails. Default: true - `first-option` - a string to be used for an extra option in the first position. E.g. "Please choose..." - `first-value` - the value to be used with the `first-option`. Typically not used, meaning the option has a blank value. --> <def tag="input" for="HoboFields::Types::EnumString" attrs="labels, titleize, first-option, first-value"><% labels ||= {} labels = HashWithIndifferentAccess.new(labels) titleize = true if titleize.nil? && labels.empty? options = this_type.values.map {|v| default = labels[v] || v default = default.titleize if titleize [I18n.t("activerecord.attributes.#{this_parent.class.to_s.downcase}/#{this_field}s.#{v}", :default => default), v] } %> <select name="#{param_name_for_this}" merge-attrs> <option value="#{first_value}" unless="&first_option.nil?"><first-option/></option> <%= options_for_select(options, this) %> </select> </def>
Version data entries
30 entries across 30 versions & 1 rubygems