Search code examples
ruby-on-railsrubyruby-on-rails-4blockdelimiter

How to add a delimiter/separator to a Rails block


I have the following block:

<% @place.each do |f| %>
  <%= f.name %><br>
  <%= f.type %>
<% end %>

which prints horizontally using display: inline-block. How can I add a seperator or delimiter in between each pair, but not after the last one?

It should look something like this:

printout - printout - printout - printout

Solution

  • A common approach, without a counter:

    <% @place.each do |f| %>
      <%= f.name %><br>
      <%= f.type %>
      <% if f != @place.last %>
        <div class="delimiter">-</div>
      <% end %>
    <% end %>