ViewComponent/view_component · error · ViewComponent::InvalidSlotNameError

Slot cannot start with 'call_'. Please rename #{slot_name}

Error message

Slot cannot start with 'call_'. Please rename #{slot_name}

What it means

Raised when a slot name starts with call_ (lib/view_component/slotable.rb:341-345). ViewComponent derives several method names from every slot: the with_<name> setter, the with_<name>_content setter, the reader, the predicate, and internal call helpers for lambda-backed slots such as the method defined as _call_<name> in __vc_define_slot (lib/view_component/slotable.rb:296). The call_ prefix is reserved to keep that generated namespace free of collisions. Unlike the neighboring errors this one is raised as a plain InvalidSlotNameError with an inline message.

Source

Thrown at lib/view_component/slotable.rb:343

        __vc_raise_if_slot_conflicts_with_call(slot_name)
        __vc_raise_if_slot_ends_with_question_mark(slot_name)
        __vc_raise_if_slot_registered(slot_name)
      end

      def __vc_raise_if_slot_registered(slot_name)
        if registered_slots.key?(slot_name)
          raise RedefinedSlotError.new(name, slot_name)
        end
      end

      def __vc_raise_if_slot_ends_with_question_mark(slot_name)
        raise SlotPredicateNameError.new(name, slot_name) if slot_name.to_s.end_with?("?")
      end

      def __vc_raise_if_slot_conflicts_with_call(slot_name)
        if slot_name.start_with?("call_")
          raise InvalidSlotNameError, "Slot cannot start with 'call_'. Please rename #{slot_name}"
        end
      end

      def __vc_raise_if_slot_name_uncountable(slot_name)
        slot_name = slot_name.to_s
        if slot_name.pluralize == slot_name.singularize
          raise UncountableSlotNameError.new(name, slot_name)
        end
      end
    end

    def __vc_get_slot(slot_name)
      @__vc_set_slots ||= {}
      content unless defined?(@__vc_content_evaluated) && @__vc_content_evaluated # ensure content is loaded so slots will be defined

      # If the slot is set, return it
      return @__vc_set_slots[slot_name] if @__vc_set_slots[slot_name]

View on GitHub (pinned to 9f22c36fa7)

Solutions

  1. Rename the slot, for example :cta, :action or :callback (callback does not start with call_)
  2. When the slot mirrors a model attribute named call_something, map it to a different slot name explicitly at the call site

Example fix

# before
class HeroComponent < ViewComponent::Base
  renders_one :call_to_action, ButtonComponent # raises InvalidSlotNameError
end

# after
class HeroComponent < ViewComponent::Base
  renders_one :cta, ButtonComponent
end
Defensive patterns

Strategy: validation

Validate before calling

def slot_name_safe?(name)
  !name.to_s.start_with?("call_")
end

slot_name_safe?(:call_to_action) # => false

Try / catch

begin
  renders_one(candidate.to_sym)
rescue ViewComponent::InvalidSlotNameError => e
  raise unless candidate.to_s.start_with?("call_")
  candidate = :cta
  retry
end

Prevention

When it happens

Trigger: renders_one :call_to_action, renders_many :call_logs, or any name whose first five characters are call_, passed to either macro. The check runs inside both validators, so singular and plural forms are equally affected.

Common situations: Marketing and hero components with a call_to_action slot, the most natural name that trips this rule; dialer and support tools with attributes such as call_notes or call_status copied from columns or routes into slots.

Related errors


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