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
- In a new rails app run
$ rails generate component inline_component - Define the method
callin InlineComponent, returning any markup:
def call
link_to "Somewhere", some_url
end
- 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 %>
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (17 by maintainers)
@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.@joelhawksley I might hold off on documenting this feature until this bug has been addressed or clarified.