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/perus/server/form.rb', line 9
def field(field, type = nil, options = nil)
field = field.to_s
if type.nil?
if @record.class.association_reflections.include?(field.to_sym)
type = 'association'
else
type = @record.db_schema[field.to_sym][:db_type]
end
end
html = "<p><label for=\"#{field}\">#{field.titlecase}:</label><span>"
case type
when 'varchar(255)'
html << input(field, options)
when 'text'
html << textarea(field, options)
when 'association'
html << association(field, options)
when 'select'
html << select(field, options)
end
html << "</span></p>" << errors_for(field)
end
|