Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/enum_select_rails/action_view_ext.rb

Instance Method Summary collapse

Instance Method Details

#enum_select(record, options = {}, html_options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/enum_select_rails/action_view_ext.rb', line 2

def enum_select(record, options = {}, html_options = {})
  pluralized = record.to_s.pluralize
  klass = self.object.class
  base = klass.send(pluralized)

  # check i18n
  i18n_method = "#{pluralized}_i18n".to_sym
  if klass.methods.include? i18n_method
    i18n = klass.send(i18n_method)
    select record.to_sym, base.keys.map {|k| [i18n[k], k]}, options, html_options
  else
    select record.to_sym, base.keys.map {|k| [k, k]}, options, html_options
  end
end