0

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?

4

2 回答 2

3

您可以使用<br />. 以下应该有效:

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

另外,请使用raw帮助程序,以免输出被转义。

于 2013-07-24T18:25:03.367 回答
0

我猜你正在寻找这个:

<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>
于 2013-07-24T18:51:38.533 回答