{"record":{"id":"3fa422ca9fa12998","repo":"heartcombo/simple_form","slug":"you-need-to-give-to-as-option-to-map-type","errorCode":null,"errorMessage":"You need to give :to as option to map_type","messagePattern":"You need to give :to as option to map_type","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/simple_form/map_type.rb","lineNumber":13,"sourceCode":"# frozen_string_literal: true\nrequire 'active_support/core_ext/class/attribute'\n\nmodule SimpleForm\n  module MapType\n    def self.extended(base)\n      base.class_attribute :mappings\n      base.mappings = {}\n    end\n\n    def map_type(*types)\n      map_to = types.extract_options![:to]\n      raise ArgumentError, \"You need to give :to as option to map_type\" unless map_to\n      self.mappings = mappings.merge types.each_with_object({}) { |t, m| m[t] = map_to }\n    end\n  end\nend\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/heartcombo/simple_form/blob/18f38aad0bdeca2ba1815043b94d96fdbbe6a325/lib/simple_form/map_type.rb#L1-L18","documentation":"map_type (from SimpleForm::MapType, extended by SimpleForm::FormBuilder — see form_builder.rb:18,21-35) registers mappings from attribute types to input classes. The trailing options hash must contain :to, the target input; without it there is nothing to map to, so ArgumentError is raised immediately at configuration time (lib/simple_form/map_type.rb:13).","triggerScenarios":"SimpleForm::FormBuilder.map_type :money with no trailing hash; passing the target positionally (map_type :money, MoneyInput) instead of as to:; passing to: nil; a typo like into: or input: instead of to:.","commonSituations":"Copy-pasting custom-input docs and dropping the trailing options hash; adding a type mapping during an upgrade and forgetting the target; assuming map_type infers a default target input.","solutions":["Pass the target as the :to option: SimpleForm::FormBuilder.map_type :money, to: :string","If you want a custom input class, point :to at it: map_type :money, to: MoneyInput (the class must be loaded)","Re-check the syntax against the built-in mappings in lib/simple_form/form_builder.rb:21-35"],"exampleFix":"# before\nSimpleForm::FormBuilder.map_type :money\n# ArgumentError: You need to give :to as option to map_type\n\n# after\nSimpleForm::FormBuilder.map_type :money, to: :string\n# or target a custom input class\nSimpleForm::FormBuilder.map_type :money, to: MoneyInput","handlingStrategy":"validation","validationCode":"# keep all custom mappings in one hash so :to can never be forgotten\ncustom_mappings = { money: :string, ssn: :password }\ncustom_mappings.each do |type, target|\n  raise ArgumentError, \"map_type :#{type} is missing :to\" if target.nil?\n  SimpleForm::FormBuilder.map_type type, to: target\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare custom type mappings in a single type => input hash in the initializer","Mirror the syntax of the built-in mappings in lib/simple_form/form_builder.rb","Boot the app (or `rails runner` the initializer) in CI so configuration errors surface at build time"],"tags":["simple-form","map-type","argument-error","configuration","custom-input"],"backgroundTag":"missing-required-option","analyzedSha":"18f38aad0bdeca2ba1815043b94d96fdbbe6a325","analyzedAt":"2026-08-21T18:23:08.988Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}