diff --git a/TODO.rdoc b/TODO.rdoc index 71541506..ea83d9d0 100644 --- a/TODO.rdoc +++ b/TODO.rdoc @@ -5,12 +5,13 @@ * Sample CSS * Test forms with non objects * Get default string options from column definition -* Improve input_type heuristic (but do not :integer, :float and :decimal to numeric, for example) +* Improve input_type heuristic * Detect label and values automatically * Add support to default :include_blank * Add support to default label method * Add wrapper support * Improve readme with examples +* :country, :time_zone and :file support == Associations diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index f97799b8..e8a2e94f 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -12,7 +12,7 @@ module SimpleForm attr_reader :template def input(attribute, options={}) - input_type = (options[:as] || default_input_type(attribute)).to_sym + input_type = default_input_type(attribute, options) pieces = self.components.collect do |klass| next if options[klass.basename] == false @@ -24,7 +24,10 @@ module SimpleForm private - def default_input_type(attribute) + def default_input_type(attribute, options) + return options[:as].to_sym if options[:as] + return :select if options[:collection] + column = @object.column_for_attribute(attribute) input_type = column.type diff --git a/test/form_builder_test.rb b/test/form_builder_test.rb index 0ec059ed..fd5cb714 100644 --- a/test/form_builder_test.rb +++ b/test/form_builder_test.rb @@ -58,6 +58,11 @@ class FormBuilderTest < ActionView::TestCase assert_select 'form select#user_updated_at_1i.datetime' end + test 'build should generate select if a collection is given' do + with_form_for :age, :collection => 1..60 + assert_select 'form select#user_age.select' + end + test 'builder should allow overriding default input type for text' do with_form_for :name, :as => :text assert_no_select 'form input#user_name'