{"action":"created","issue":{"url":"https://api.github.com/repos/justinfrench/formtastic/issues/1146","labels_url":"https://api.github.com/repos/justinfrench/formtastic/issues/1146/labels{/name}","comments_url":"https://api.github.com/repos/justinfrench/formtastic/issues/1146/comments","events_url":"https://api.github.com/repos/justinfrench/formtastic/issues/1146/events","html_url":"https://github.com/justinfrench/formtastic/issues/1146","id":66717646,"number":1146,"title":"We should fallback to StringInput for unknown column types","user":{"login":"justinfrench","id":5240,"avatar_url":"https://avatars.githubusercontent.com/u/5240?v=3","gravatar_id":"","url":"https://api.github.com/users/justinfrench","html_url":"https://github.com/justinfrench","followers_url":"https://api.github.com/users/justinfrench/followers","following_url":"https://api.github.com/users/justinfrench/following{/other_user}","gists_url":"https://api.github.com/users/justinfrench/gists{/gist_id}","starred_url":"https://api.github.com/users/justinfrench/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinfrench/subscriptions","organizations_url":"https://api.github.com/users/justinfrench/orgs","repos_url":"https://api.github.com/users/justinfrench/repos","events_url":"https://api.github.com/users/justinfrench/events{/privacy}","received_events_url":"https://api.github.com/users/justinfrench/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/justinfrench/formtastic/labels/feature","name":"feature","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-06T22:13:08Z","updated_at":"2015-04-07T07:52:30Z","closed_at":null,"body":"When trying to find the most suitable input type for a given attribute, we often look to the type of database field. The current implementation doesn't have a fallback, which means we're constantly playing catch-up to add explicit mappings for column types that ActiveRecord supports.\r\n\r\nIf you have a database column type of `foo`, our fallback is to try `FooInput` if there's no explicit mapping, leading to an `unknown input` exception.\r\n\r\nHere's the relevant code:\r\n\r\n```ruby\r\n# default is a :string, a similar behaviour to Rails' scaffolding.\r\ndef default_input_type(method, options = {}) # @private\r\n  if @object\r\n    return :select  if reflection_for(method)\r\n\r\n    return :file    if is_file?(method, options)\r\n  end\r\n\r\n  if column = column_for(method)\r\n    # Special cases where the column type doesn't map to an input method.\r\n    case column.type\r\n    when :string\r\n      return :password  if method.to_s =~ /password/\r\n      return :country   if method.to_s =~ /country$/\r\n      return :time_zone if method.to_s =~ /time_zone/\r\n      return :email     if method.to_s =~ /email/\r\n      return :url       if method.to_s =~ /^url$|^website$|_url$/\r\n      return :phone     if method.to_s =~ /(phone|fax)/\r\n      return :search    if method.to_s =~ /^search$/\r\n      return :color     if method.to_s =~ /color/\r\n    when :integer\r\n      return :select    if reflection_for(method)\r\n      return :select    if enum_for(method)\r\n      return :number\r\n    when :float, :decimal\r\n      return :number\r\n    when :datetime, :timestamp\r\n      return :datetime_select\r\n    when :time\r\n      return :time_select\r\n    when :date\r\n      return :date_select\r\n    end\r\n\r\n    # Try look for hints in options hash. Quite common senario: Enum keys stored as string in the database.\r\n    return :select    if column.type == :string && options.key?(:collection)\r\n    # Try 3: Assume the input name will be the same as the column type (e.g. string_input).\r\n    return column.type\r\n  else\r\n    return :select    if options.key?(:collection)\r\n    return :password  if method.to_s =~ /password/\r\n    return :string\r\n  end\r\nend\r\n```\r\n\r\nThe problem is this line:\r\n\r\n```ruby\r\nreturn column.type\r\n```\r\n\r\nI think this needs to be `return :string`, but before that happens, we'd need to ensure we have explicit mappings from any column types we know about (anything previously caught by `return column.type`), so that `StringInput` is the fallback, instead of `WhateverInput`.\r\n\r\nHere's the replacement code with one line change and a TODO for where the extra mappings would go:\r\n\r\n```ruby\r\n# default is a :string, a similar behaviour to Rails' scaffolding.\r\ndef default_input_type(method, options = {}) # @private\r\n  if @object\r\n    return :select  if reflection_for(method)\r\n\r\n    return :file    if is_file?(method, options)\r\n  end\r\n\r\n  if column = column_for(method)\r\n    # Special cases where the column type doesn't map to an input method.\r\n    case column.type\r\n    when :string\r\n      return :password  if method.to_s =~ /password/\r\n      return :country   if method.to_s =~ /country$/\r\n      return :time_zone if method.to_s =~ /time_zone/\r\n      return :email     if method.to_s =~ /email/\r\n      return :url       if method.to_s =~ /^url$|^website$|_url$/\r\n      return :phone     if method.to_s =~ /(phone|fax)/\r\n      return :search    if method.to_s =~ /^search$/\r\n      return :color     if method.to_s =~ /color/\r\n    when :integer\r\n      return :select    if reflection_for(method)\r\n      return :select    if enum_for(method)\r\n      return :number\r\n    when :float, :decimal\r\n      return :number\r\n    when :datetime, :timestamp\r\n      return :datetime_select\r\n    when :time\r\n      return :time_select\r\n    when :date\r\n      return :date_select\r\n    # TODO add explicit mappings to all known column types that we support here\r\n    # when :x\r\n    #   return :y\r\n    # when :y\r\n    #   return :z\r\n    end\r\n\r\n    # Try look for hints in options hash. Quite common senario: Enum keys stored as string in the database.\r\n    return :select    if column.type == :string && options.key?(:collection)\r\n    \r\n    # Fallback to :string if we don't explicitly handle this `column.type`\r\n    return :string\r\n  else\r\n    return :select    if options.key?(:collection)\r\n    return :password  if method.to_s =~ /password/\r\n    return :string\r\n  end\r\nend\r\n```\r\n\r\nAnyone interested in working up a patch?\r\n\r\ncc @timoschilling @mitio"},"comment":{"url":"https://api.github.com/repos/justinfrench/formtastic/issues/comments/90434451","html_url":"https://github.com/justinfrench/formtastic/issues/1146#issuecomment-90434451","issue_url":"https://api.github.com/repos/justinfrench/formtastic/issues/1146","id":90434451,"user":{"login":"mitio","id":129307,"avatar_url":"https://avatars.githubusercontent.com/u/129307?v=3","gravatar_id":"","url":"https://api.github.com/users/mitio","html_url":"https://github.com/mitio","followers_url":"https://api.github.com/users/mitio/followers","following_url":"https://api.github.com/users/mitio/following{/other_user}","gists_url":"https://api.github.com/users/mitio/gists{/gist_id}","starred_url":"https://api.github.com/users/mitio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitio/subscriptions","organizations_url":"https://api.github.com/users/mitio/orgs","repos_url":"https://api.github.com/users/mitio/repos","events_url":"https://api.github.com/users/mitio/events{/privacy}","received_events_url":"https://api.github.com/users/mitio/received_events","type":"User","site_admin":false},"created_at":"2015-04-07T07:52:30Z","updated_at":"2015-04-07T07:52:30Z","body":"Will this prevent people from the possibility to define a custom input type, say `InetInput`? If so, can it first check if there is a constant which defines the given input type and if so, to just keep it as its original type?"}}