{"record":{"id":"0ca656414254b1fd","repo":"ViewComponent/view_component","slug":"wrong-number-of-arguments-given-args-size-exp","errorCode":null,"errorMessage":"wrong number of arguments (given #{args.size}, expected 1)","messagePattern":"wrong number of arguments \\(given #(.+?), expected 1\\)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/view_component/inline_template.rb","lineNumber":18,"sourceCode":"# frozen_string_literal: true\n\nmodule ViewComponent # :nodoc:\n  module InlineTemplate\n    extend ActiveSupport::Concern\n\n    Template = Struct.new(:source, :language, :path, :lineno)\n\n    class_methods do\n      def method_missing(method, *args)\n        return super if !method.end_with?(\"_template\")\n\n        if defined?(@__vc_inline_template_defined) && @__vc_inline_template_defined\n          raise MultipleInlineTemplatesError\n        end\n\n        if args.size != 1\n          raise ArgumentError, \"wrong number of arguments (given #{args.size}, expected 1)\"\n        end\n\n        ext = method.to_s.gsub(\"_template\", \"\")\n        template = args.first\n\n        @__vc_inline_template_language = ext\n\n        caller = caller_locations(1..1)[0]\n        @__vc_inline_template = Template.new(\n          template,\n          ext,\n          caller.absolute_path || caller.path,\n          caller.lineno\n        )\n\n        @__vc_inline_template_defined = true\n      end\n","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/ViewComponent/view_component/blob/9f22c36fa7d7b44098a8ed97472e3b4674ae420f/lib/view_component/inline_template.rb#L1-L36","documentation":"Inline template DSL methods (erb_template, haml_template, slim_template, ...) are captured by method_missing in ViewComponent::InlineTemplate and accept exactly one argument: the template source string. Passing zero arguments or more than one raises ArgumentError ('wrong number of arguments (given N, expected 1)') before any template is stored. Note the arity check runs after the duplicate-template check, so a clean class with a bad call fails here.","triggerScenarios":"Calling erb_template with no source (forgot the heredoc); passing multiple strings like erb_template \"<div>\", \"</div>\"; passing options as a second positional argument (erb_template source, format: :html) instead of putting everything in the one string.","commonSituations":"Refactoring a heredoc and accidentally deleting the argument; developers assuming the DSL takes keyword options like template handlers do; copy-paste from Rails renderer docs where render takes multiple args.","solutions":["Pass exactly one String containing the full template source: erb_template <<-ERB ... ERB.","If you need per-call options, encode them in the method suffix (haml_template/slim_template selects the language) rather than extra arguments.","If the template is long or needs options, move it to a template file under app/components/<name>/ and drop the inline call."],"exampleFix":"# before\nclass BadgeComponent < ViewComponent::Base\n  erb_template # missing source\nend\n\n# after\nclass BadgeComponent < ViewComponent::Base\n  erb_template <<-ERB\n    <span class=\"badge\"><%= content %></span>\n  ERB\nend","handlingStrategy":"validation","validationCode":"source = \"<div>...</div>\"\nraise ArgumentError, \"template source must be a single String\" unless source.is_a?(String)\n\nCardComponent.erb_template(source)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use a heredoc (<<-ERB ... ERB) for the single argument so it is visually obvious.","Remember the language comes from the method name (erb_/haml_/slim_template), not extra args."],"tags":["view-component","ruby-on-rails","inline-template","argument-error","ruby"],"backgroundTag":"wrong-number-of-arguments","analyzedSha":"9f22c36fa7d7b44098a8ed97472e3b4674ae420f","analyzedAt":"2026-08-23T10:20:47.008Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}