大筋一緒なんですが
私はこういうヘルパーを作って
def options_for_select_from_enum(klass, target)
enum_list = klass.send(target.to_s.pluralize.to_s)
enum_list.map do |key, _value|
[klass.human_attribute_name(key), key]
end
end
こうやって使ってます(simple_form)
= f.input :state, collection: options_for_select_from_enum(Book, :state)
ちなみにransackの検索ではこう
def options_for_select_from_enum_number(klass, target)
enum_list = klass.send(target.to_s.pluralize.to_s)
enum_list.keys.map { |key| klass.human_attribute_name(key) }.zip(enum_list.values)
end
= search_form_for @q, :builder => SimpleForm::FormBuilder do |f|
= f.input :state_eq, collection: options_for_select_from_enum_number(Book, :state)