Permalink
Browse files

Small refactor: file_method? is better returning a boolean than the i…

…nput type
  • Loading branch information...
1 parent fcf22c4 commit c61b7499a5ac81452be41c15e0a5144248c1a40b @carlosantoniodasilva carlosantoniodasilva committed Feb 7, 2011
Showing with 3 additions and 6 deletions.
  1. +3 −6 lib/simple_form/form_builder.rb
@@ -265,33 +265,30 @@ def default_input_type(attribute_name, column, options) #:nodoc:
when /phone/ then :tel
when /url/ then :url
else
- file_method?(attribute_name) || input_type || :string
+ file_method?(attribute_name) ? :file : (input_type || :string)
end
else
input_type
end
end
- def find_custom_type(attribute_name)
+ def find_custom_type(attribute_name) #:nodoc:
SimpleForm.input_mappings.find { |match, type|
attribute_name =~ match
}.try(:last) if SimpleForm.input_mappings
end
- # Checks if attribute is a file_method.
def file_method?(attribute_name) #:nodoc:
file = @object.send(attribute_name) if @object.respond_to?(attribute_name)
- :file if file && SimpleForm.file_methods.any? { |m| file.respond_to?(m) }
+ file && SimpleForm.file_methods.any? { |m| file.respond_to?(m) }
end
- # Finds the database column for the given attribute.
def find_attribute_column(attribute_name) #:nodoc:
if @object.respond_to?(:column_for_attribute)
@object.column_for_attribute(attribute_name)
end
end
- # Find reflection related to association.
def find_association_reflection(association) #:nodoc:
if @object.class.respond_to?(:reflect_on_association)
@object.class.reflect_on_association(association)

0 comments on commit c61b749

Please sign in to comment.