8
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
36
37
38
39
40
|
# File 'lib/date_checkbox/has_date_checkbox.rb', line 8
def has_date_checkbox(db_field)
column_name = db_field
method_name = db_field.to_s.sub(/_at$/, '')
class_eval do
define_method("#{method_name}") do
if attribute_present?(column_name)
"1" else
"0" end
end
define_method("#{method_name}?") do
attribute_present?(column_name)
end
define_method("#{method_name}=") do |value|
if value.to_s == "0"
write_attribute(column_name, nil)
else
write_attribute(column_name, Time.now)
end
end
end
end
|