ViewComponent/view_component · error · AbstractController::ActionNotFound

Component preview '#{params[:path]}' not found.

Error message

Component preview '#{params[:path]}' not found.

What it means

Error "Component preview '#{params[:path]}' not found." thrown in ViewComponent/view_component.

Source

Thrown at app/controllers/concerns/view_component/preview_actions.rb:70

    # :doc:
    def previews_enabled?
      ViewComponent::Base.config.previews.enabled
    end

    # :doc:
    def find_preview
      candidates = []
      params[:path].to_s.scan(%r{/|$}) { candidates << Regexp.last_match.pre_match }
      preview = candidates.sort_by(&:length).reverse_each.detect { |candidate| ViewComponent::Preview.exists?(candidate) }

      if preview
        @preview = ViewComponent::Preview.find(preview)
      else
        # TODO: This branch is covered in #test_returns_404_when_preview_does_not_exist,
        # but Simplecov doesn't always mark it as covered.
        # :nocov:
        raise AbstractController::ActionNotFound, "Component preview '#{params[:path]}' not found."
        # :nocov:
      end
    end

    def set_locale(&block)
      I18n.with_locale(params[:locale] || I18n.default_locale, &block)
    end

    # Returns either {} or {layout: value} depending on configuration
    def determine_layout(layout_override = nil, prepend_views: true)
      return {} unless defined?(Rails.root)

      layout_declaration = {}

      if !layout_override.nil?
        # Allow component-level override, even if false (thus no layout rendered)
        layout_declaration[:layout] = layout_override
      elsif default_preview_layout.present?

View on GitHub (pinned to 9f22c36fa7)

Solutions

  1. Verify the preview path matches a file in the configured preview paths (config.view_component.preview_paths): the file must be named *_preview.rb and the lookup path is the file name without that suffix.
  2. Add the preview's directory to config.view_component.preview_paths in config/environments/development.rb (or test.rb) if using a custom location.
  3. Restart the server after adding new preview files or paths; in eager-loaded environments new previews are not discovered at runtime.

When it happens

Trigger: Thrown at app/controllers/concerns/view_component/preview_actions.rb:70 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/9885447f088691b4. Report an issue: GitHub.