Skip to content

renders_many - Is there anyway to tell whether a single child or an array of children are to be rendered? #1045

Answered by boardfish
brandoncordell asked this question in Q&A
Discussion options

You must be logged in to vote

Haven't tested this, but I think it might work.

In your component template:

<% if items.one? %>
  <%= items.compact.first %>
<% else %>
  <% items.each do |item| %>
    <div><%= item %></div>
  <% end %>
<% end %>

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@boardfish
Comment options

@boardfish
Comment options

@boardfish
Comment options

@brandoncordell
Comment options

@boardfish
Comment options

Answer selected by boardfish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants