25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/admin_assistant/association_target.rb', line 25
def options_for_select
records = @associated_class.find(:all)
name_method = default_name_method
if name_method.nil? and
records.first.respond_to?(:name_for_admin_assistant)
name_method = :name_for_admin_assistant
end
sort_value_method = nil
if records.first.respond_to?(:sort_value_for_admin_assistant)
sort_value_method = :sort_value_for_admin_assistant
else
sort_value_method = name_method
end
if sort_value_method
records = records.sort_by { |model| model.send(sort_value_method) }
end
if name_method
records.map { |model| [model.send(name_method), model.id] }
else
records.map &:id
end
end
|