def auto_field(field, options={})
column = @object.class.columns.select { |col|
col.name.to_s == field.to_s}.first
field = field.to_s
if !column
if @object.respond_to?(field) and
@object.connection.tables.include?(field) and
model = field.camelcase.singularize.constantize
return checkbox_group(field, model.find(:all), options)
else
raise(NoMethodError,
_('Field %s not defined for %s') % [field, @object.class])
end
end
if field == 'id'
return info_row(field, options)
elsif field == 'passwd'
options[:value] = ''
return password_field(field, options)
elsif field =~ /_id$/ and column.type == :integer and
model = table_from_field(field)
choices = model.qualified_collection_by_id
return select(field,
choices.map {|it| [Translation.for(it[0]), it[1]]},
{:include_blank => true})
end
case column.type.to_sym
when :string
return text_field(field, options)
when :text
options[:size] ||= '70x15'
return text_area(field, options)
when :integer, :decimal, :float
options[:class] ||= 'numeric'
return text_field(field, options)
when :boolean
return radio_group(field, [[_('Yes'), true], [_('No'), false]],
options)
when :date
return date_field(field, options)
when :datetime
return datetime_select(field, options)
else
return info_row(field, options)
end
end