Give :collection is enough to active :select type.
This commit is contained in:
parent
001204f599
commit
728dd5ba45
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue