heartcombo/simple_form · error · ArgumentError
You need to give :to as option to map_type
Error message
You need to give :to as option to map_type
What it means
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).
Source
Thrown at lib/simple_form/map_type.rb:13
# frozen_string_literal: true
require 'active_support/core_ext/class/attribute'
module SimpleForm
module MapType
def self.extended(base)
base.class_attribute :mappings
base.mappings = {}
end
def map_type(*types)
map_to = types.extract_options![:to]
raise ArgumentError, "You need to give :to as option to map_type" unless map_to
self.mappings = mappings.merge types.each_with_object({}) { |t, m| m[t] = map_to }
end
end
end
View on GitHub (pinned to 18f38aad0b)
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
Example fix
# before SimpleForm::FormBuilder.map_type :money # ArgumentError: You need to give :to as option to map_type # after SimpleForm::FormBuilder.map_type :money, to: :string # or target a custom input class SimpleForm::FormBuilder.map_type :money, to: MoneyInput
Defensive patterns
Strategy: validation
Validate before calling
# keep all custom mappings in one hash so :to can never be forgotten
custom_mappings = { money: :string, ssn: :password }
custom_mappings.each do |type, target|
raise ArgumentError, "map_type :#{type} is missing :to" if target.nil?
SimpleForm::FormBuilder.map_type type, to: target
end Prevention
- 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
When it happens
Trigger: 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:.
Common situations: 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.
Related errors
- A block is required as argument to wrapper
- Couldn't find wrapper with name #{name}
- Association cannot be used in forms not associated with an o
- :has_one associations are not supported by f.association
- input should be implemented by classes inheriting from Colle
AI-assisted analysis of heartcombo/simple_form@18f38aad0b (2026-08-21).
Data as JSON: /api/errors/3fa422ca9fa12998.
Report an issue: GitHub.