DEV Community

Discussion on: Advanced ViewComponent patterns in Rails

Collapse
amree profile image
Amree Zaid

I wonder why are you using ApplicationComponent in the HTML instead of SubheadComponent itself. I noticed GitHub Primer is doing the same thing. Care to explain?

<%=# app/components/subhead_component.html.erb %>

<%= render ApplicationComponent.new(**@options) do %>
  <%= heading %>
  <%= description %>
<% end %>
Enter fullscreen mode Exit fullscreen mode
Collapse
abeidahmed profile image
Abeid Ahmed Author

Yes, because SubheadComponent class does not have the call method defined. When you're passing in a block, Ruby looks for a call method.
Instead of defining call method for each of the components, you can simplify define in your top level class and refer that class.