lib/formtastic/helpers/input_helper.rb in formtastic-2.0.0.rc3 vs lib/formtastic/helpers/input_helper.rb in formtastic-2.0.0.rc4
- old
+ new
@@ -265,18 +265,27 @@
klass.new(self, template, @object, @object_name, method, options).to_html
end
protected
+ # First try if we can detect special things like :file. With CarrierWave the method does have
+ # an underlying column so we don't want :string to get selected.
+ #
# For methods that have a database column, take a best guess as to what the input method
# should be. In most cases, it will just return the column type (eg :string), but for special
# cases it will simplify (like the case of :integer, :float & :decimal to :number), or do
# something different (like :password and :select).
#
# If there is no column for the method (eg "virtual columns" with an attr_accessor), the
# default is a :string, a similar behaviour to Rails' scaffolding.
def default_input_type(method, options = {}) #:nodoc:
+ if @object
+ return :select if reflection_for(method)
+
+ return :file if is_file?(method, options)
+ end
+
if column = column_for(method)
# Special cases where the column type doesn't map to an input method.
case column.type
when :string
return :password if method.to_s =~ /password/
@@ -298,16 +307,10 @@
# Try look for hints in options hash. Quite common senario: Enum keys stored as string in the database.
return :select if column.type == :string && options.key?(:collection)
# Try 3: Assume the input name will be the same as the column type (e.g. string_input).
return column.type
else
- if @object
- return :select if reflection_for(method)
-
- return :file if is_file?(method, options)
- end
-
return :select if options.key?(:collection)
return :password if method.to_s =~ /password/
return :string
end
end
@@ -361,6 +364,5 @@
end
end
end
end
-
\ No newline at end of file