Rails,连接2个变量并在视图中显示它们

时间:2016-03-05 19:55:54

标签: ruby-on-rails view concatenation

提前感谢您的帮助! 我想连接2个变量并在视图中的表中的一个单元格中显示。更具体地说,我想显示列“游戏得分”,例如5:7连接@ game.team1_score和@ game.team2_score。 你能帮忙解决这个问题吗?

 <% @games.each do |game| %><tbody>
<tr>
  <td><%= game.id %> </td>
  <td><%= game.team1 %></td>
  <td><%= game.team2 %></td>
  <td><%= game.team1_score ":" game.team2_score %></td>
  <td><%= game.updated_at %></td>
  <td><%=link_to("Detail", game_path(game.id), class: 'action show') %></td>
  <td><%=link_to("Edit", edit_game_path(game.id), class: 'action edit') %></td>
  <td><%=link_to("Delete", game_path(game.id), method: :delete, class: 'action delete') %> <br></td>
  <% end %>
</tr>

1 个答案:

答案 0 :(得分:0)

试试这个!

<td><%= game.team1_score %>:<%= game.team2_score %></td>