question.rb
1.93 KB
1
2
3
4
5
6
7
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module Surveyable
class Question < ActiveRecord::Base
include RankedModel
ranks :position
belongs_to :survey, polymorphic: true
has_many :answers, :dependent => :restrict_with_error
has_many :answer_choices, dependent: :destroy
STI_TYPES = %w[InfoField HiddenField BooleanField DateField SingleSelectField MultiSelectField TextField StringField IntegerField MoneyAmountField SingleDocumentField MultiDocumentField TelephoneField RelationshipSelectField]
accepts_nested_attributes_for :answer_choices, :allow_destroy => true,
:reject_if => lambda { |a| a[:text].blank? }
validates_presence_of :text
validates_presence_of :type
scope :required, -> { where(required:true)}
def field_type
'text'
end
end
class InfoField < Question
def field_type
'noAnswer'
end
end
class HiddenField < Question
def field_type
'hidden'
end
end
class BooleanField < Question
def field_type
'boolean'
end
end
class DateField < Question
def field_type
'date'
end
end
class SingleSelectField < Question
def field_type
'radio'
end
end
class RelationshipSelectField < SingleSelectField
def field_type
'relation'
end
end
class MultiSelectField < Question
def field_type
'select'
end
end
class TextField < Question
def field_type
'textarea'
end
end
class StringField < Question
def field_type
'text'
end
end
class IntegerField < Question
def field_type
'number'
end
end
class MoneyAmountField < Question
def field_type
'money'
end
end
class SingleDocumentField < Question
def field_type
'file'
end
end
class MultiDocumentField < Question
def field_type
'multifile'
end
end
class TelephoneField < Question
def field_type
'tel'
end
end
end