user4219892
user4219892

Reputation:

Erb: How to make a block repeat horizontally?

If I have a block of the following format:

<% @model.each do |f| %>
  <%= f.name %>
  <%= image_tag("some_picture.jpg") %>
  <br>
<% end %>

How do I get it to repeat itself horizontally, instead of vertically? If the list is long enough to reach the end of its containing div, I would like for it to continue a line down, like normal html text.

Upvotes: 1

Views: 267

Answers (1)

vee
vee

Reputation: 38645

This concatenates the names array using Array#join with a single space between them:

<%= @model.map(&:name).join(' ') %>

Wrapping this within a paragraph element would give you what you are looking for:

<%= content_tag(:p, @model.map(&:name).join(' ')) %>

Upvotes: 2

Related Questions