Replace all instances of render Box inside app/views/demo/benchmark.html.erb with render(BoxComponent.new), as shown:
# app/views/demo/benchmark.html.erb
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<%= render(BoxComponent.new) do %>
Inside a box
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
If this is not helpful please let me know how it can be improved. Thank you for the gem and for sharing so much so openly.
Steps to reproduce
Run
bin/rails server
and visitlocalhost:3000/benchmark
Expected behavior
Show view containing a series of nested boxes and terminal report stating how many times faster ViewComponent is compared to partial.
Actual behavior
Raises error "ActionView::Template::Error (uninitialized constant Box)" on line 3 of
app/views/demo/benchmark.html.erb
.System configuration
Rails version: 6.1.0
Ruby version: 3.0.0p0
Gem version: 2.25.0
Why does it happen?
This is my first time logging an issue, but I do think that
render Box
should be changed torender(BoxComponent.new)
, as is used in RailsConf 2020 CE - Encapsulating Views by Joel Hawksley.Fixing it
Replace all instances of
render Box
insideapp/views/demo/benchmark.html.erb
withrender(BoxComponent.new)
, as shown:If this is not helpful please let me know how it can be improved. Thank you for the gem and for sharing so much so openly.