10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/helpers/custom/select_helper.rb', line 10
def collection_for_select(collection, name, id, options = {})
return [] unless collection.is_a?(Array)
collection = if options[:collection_is_not_hash]
collection.map do |h|
field = h.try(name)
label = options[:i18n].present? ? options[:i18n][field] : field.capitalize
[ label, h.try(id) ]
end
else
collection.map { |h| [ h[name], h[id] ] }
end
collection.unshift [options[:blank_value_label],''] if options[:blank_value_label]
collection = options_for_select(collection, options[:value]) if options[:options_for_select].present?
collection
end
|