9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/throughcheckboxes/checkboxes_for.rb', line 9
def checkboxes_for(*relations)
klass = self
ThroughCheckboxes::Core.validate(klass, *relations)
for relation in relations
field_name="#{relation}_ids"
class_eval do
attr_accessible field_name.to_sym
end
instance_eval do
define_method "#{field_name}=" do |ids|
send("#{relation}=",ids.select { |id| id.present? }.map {|id| ThroughCheckboxes::Core.relation_klass(klass, relation).find(id)})
end
define_method field_name do
send("#{relation}").map {|e| e.id}
end
end
end
end
|