view_component: Unable to render Inline Component Variants

Hello and thank you for work on this amazing library!

Having a blast so far, but am unable to render inline components per the documentation.

I’ve attached a code snippet and a screenshot at the bottom.

Steps to reproduce

  1. In a new rails app run $ rails generate component inline_component
  2. Define the method call in InlineComponent, returning any markup:
def call
  link_to "Somewhere", some_url
end
  1. Render the component in a view:
<%= render InlineComponent.new.call %>

Expected behavior

The component should render whatever call returns.

Actual behavior

ActionView raises ActionView::MissingTemplate, stating is it missing a partial and referencing the return line in call

System configuration

Rails version: 6.0.2.2 Ruby version: 2.6.5 Gem version: 2.5.1

My code:

# component.rb
class ItemLinksComponent < ViewComponent::Base
  def call
    link_to 'remove', '#', data: { action: 'nested-form#removeAssociation' }
  end
end

# view.html.erb
<%= render ItemLinksComponent.new.call %>
Screen Shot 2020-04-24 at 6 10 07 PM

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (17 by maintainers)

Most upvoted comments

@helphop You are correct, I tried passing the variant name to the component to render the variant, but it only rendered the HTML defined under call.

# component.rb
class ItemLinksComponent < ViewComponent::Base
  def call
    link_to 'remove', '#', data: { action: 'nested-form#removeAssociation' }
  end
  
  def call_phone
    link_to 'phone', '/phone'
  end
end

# view.html.erb -- RENDERS CALL, NOT VARIANT
<%= render ItemLinksComponent.new "phone" %>

@joelhawksley I might hold off on documenting this feature until this bug has been addressed or clarified.