heartcombo/simple_form · error · ArgumentError
A block is required as argument to wrapper
Error message
A block is required as argument to wrapper
What it means
Inside a config.wrappers block, b.wrapper(name, options) defines a nested group of components (a Wrappers::Many) built by yielding a fresh Builder to the block; the block is what populates the group, so calling b.wrapper without one raises ArgumentError rather than registering an empty wrapper (lib/simple_form/wrappers/builder.rb:71). Single components are added with b.use / b.optional instead.
Source
Thrown at lib/simple_form/wrappers/builder.rb:71
@components << Leaf.new(name, options)
end
end
def optional(name, options = {}, &block)
@options[name] = false
use(name, options)
end
def wrapper(name, options = nil)
if block_given?
name, options = nil, name if name.is_a?(Hash)
builder = self.class.new(@options)
options ||= {}
options[:tag] = :div if options[:tag].nil?
yield builder
@components << Many.new(name, builder.to_a, options)
else
raise ArgumentError, "A block is required as argument to wrapper"
end
end
def to_a
@components
end
end
end
end
View on GitHub (pinned to 18f38aad0b)
Solutions
- Supply a block: b.wrapper :addons do |w| w.use :prefix; w.use :input; w.use :suffix end
- If you only wanted a single component, use b.use :input (or b.optional :pattern) instead of b.wrapper
- Restart the app after fixing the initializer so the corrected wrappers are re-registered
Example fix
# before
SimpleForm.setup do |config|
config.wrappers :default do |b|
b.wrapper :addons # ArgumentError: block required
end
end
# after
SimpleForm.setup do |config|
config.wrappers :default do |b|
b.wrapper :addons do |w|
w.use :prefix
w.use :input
w.use :suffix
end
end
end Defensive patterns
Strategy: validation
Try / catch
begin
require Rails.root.join('config/initializers/simple_form')
rescue ArgumentError => e
abort "Fix config/initializers/simple_form.rb (missing block in b.wrapper?): #{e.message}"
end Prevention
- Treat b.wrapper as always taking a do...end block; use b.use / b.optional for single leaf components
- Reboot the app or run a view spec right after editing wrapper config so DSL mistakes fail early
- Keep wrapper definitions small and covered by view specs to catch merge-damage
When it happens
Trigger: config.wrappers :default do |b| b.wrapper :addons end (missing do...end); passing components as extra positional args (b.wrapper :addons, :input); confusing b.wrapper (nested group, block required) with b.use (single leaf component).
Common situations: Hand-editing a long initializer and losing the do...end; merge conflicts in wrapper config; learning the wrapper DSL and mixing up use and wrapper.
Related errors
- You need to give :to as option to map_type
- 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
- SimpleForm.include_component expects a module but got: #{com
AI-assisted analysis of heartcombo/simple_form@18f38aad0b (2026-08-21).
Data as JSON: /api/errors/48e29ab821869b74.
Report an issue: GitHub.