DEV Community

Rails Designer
Rails Designer

Posted on • Originally published at railsdesigner.com

1 1 1

Spacer Components introduced in ViewComponent 3.20

This article was originally published on Rails Designer


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)) %>
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more