1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
dans application_helper.rb
def option_from_collection_for_select_indent(collection, group_method, group_label_method, option_key_method, option_value_method,selected_key = nil, depth= 0,indent=' - ' )
collection.inject("") do |options_for_select, group|
group_id = group.send(option_key_method)
children = group.send(group_method)
options_for_select += "<option "
options_for_select += " style=\"font-weight:bold\"" if children.length > 0 or depth ==0
options_for_select += " value=\"#{group_id}\""
options_for_select += " selected=\"selected\"" if group_id == selected_key
options_for_select += ">#{indent * depth}#{group.send(group_label_method)}"
options_for_select += '</option>'
temp = depth+1
options_for_select += option_from_collection_for_select_indent(group.send(group_method), group_method, group_label_method,option_key_method, option_value_method,selected_key,temp,indent)
end
end |
Partager