SUMMER SALE Summer sale: 25% off UI Components and JavaScript for Rails Developers

Spacer Components introduced in ViewComponent 3.20

Version 3.20 of ViewComponent introduced spacer_component.

It’s a new attribute that can be added to a collection to add another component between each item of a collection. It works like this:

<%= render(ProductComponent.with_collection(@products, spacer_component: SpacerComponent.new)) %>

This will then render SpacerComponent’s between each ProductComponent. Pretty cool.

If you think, you’ve seen this feature before. You could be right. It was inspired by Rails’ collection partial rendering.

Note: I also updated the ViewComponent Cheatsheet to include it.

Published at . Last updated at . Have suggestions or improvements on this content? Do reach out.

More articles like this on modern Rails & frontend? Get them first in your inbox.
JavaScript for Rails Developers
Out now

UI components Library for Ruby on Rails apps

$ 99 one-time
payment

View components