ViewComponent/view_component · error · ViewComponent::MissingTemplateError

No templates for COMPONENT match the request DETAIL. To fix

Error message

No templates for COMPONENT match the request DETAIL.

To fix this issue, provide a suitable template.

What it means

Error "No templates for COMPONENT match the request DETAIL. To fix this issue, provide a suitable template." thrown in ViewComponent/view_component.

Source

Thrown at lib/view_component/compiler.rb:101

        template.compile_to_component
      end

      @component.silence_redefinition_of_method(:render_template_for)

      if @templates.one?
        template = @templates.first
        safe_call = template.safe_method_name_call
        @component.define_method(:render_template_for) do |_|
          @current_template = template
          instance_exec(&safe_call)
        end
      else
        compiler = self
        @component.define_method(:render_template_for) do |details|
          if (@current_template = compiler.find_templates_for(details).first)
            instance_exec(&@current_template.safe_method_name_call)
          else
            raise MissingTemplateError.new(self.class.name, details)
          end
        end
      end
    end

    def template_errors
      @_template_errors ||= begin
        errors = []

        errors << "Couldn't find a template file or inline render method for #{@component}." if @templates.empty?

        @templates
          .map { |template| [template.variant, template.format] }
          .tally
          .select { |_, count| count > 1 }
          .each do |tally|
          variant, this_format = tally.first

View on GitHub (pinned to 9f22c36fa7)

Solutions

  1. Add a template matching the requested details: for variants add e.g. my_component.html+phone.erb, for formats add e.g. my_component.json.jbuilder, for locales add a locale-scoped template.
  2. Check the request's variant/format/locale and rename the template file suffix so its variant, format, and locale match what is being requested.

When it happens

Trigger: Thrown at lib/view_component/compiler.rb:101 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ViewComponent/view_component@9f22c36fa7 (2026-08-23). Data as JSON: /api/errors/d9c53d54ee23ec2c. Report an issue: GitHub.