Bagzli
Bagzli

Reputation: 6569

Rails new line on <td>

I am trying to figure out a way I can have a new line in a cell so it is displayed in this format:

Phone Number 1
Phone Number 2
Phone Number 3

Let me show you the code that I have now so that you may understand my problem:

<tbody>
        <% @books.each do |book| %>
  <% record = AddressBookController.address_book(book.id) %>
        <tr>
            <td><%= record['last_name'] %></td>
            <td><%= record['phone_numbers'].join ', ' %></td></td>
        </tr>
        <% end %>
</tbody>

The .join will break up the array and display it like this: Phone Number 1, Phone Number 2, Phone Number 3

How can I make it show like first example in this post?

Upvotes: 0

Views: 1140

Answers (2)

Sudhir Jonathan
Sudhir Jonathan

Reputation: 17516

I guessing you're looking for this:

<tbody>
    <% @books.each do |book| %>
    <% record = AddressBookController.address_book(book.id) %>
        <% record['phone_numbers'].each do |number| %>
        <tr>
          <td><%= record['last_name'] %></td>
          <td><%= number %></td></td>
        </tr>
        <% end %>
    <% end %>
</tbody>

Upvotes: 0

vee
vee

Reputation: 38645

You can join using <br />. The following should work:

<td><%= raw record['phone_numbers'].join('<br />') %></td>

Also, use the raw helper so that the output isn't escaped.

Upvotes: 3

Related Questions