在模板中,我在行程中的某些天进行了迭代:
<%= for day <- @days do %>
<tr>
<td><%= day.number %></td>
<td><%= day.main_event_time %></td>
<td><%= day.main_event %></td>
<td><%= day.location %></td>
<td><%= day.who %></td>
<td><%= day.summary %></td>
<td><%= day.lodging %></td>
<td><%= link "Show", to: day_path(@conn, :show, day) %></td>
<td><%= link "Edit", to: day_path(@conn, :edit, day) %></td>
<td><%= link "Delete", to: day_path(@conn, :delete, day), method: :delete %></td>
</tr>
<% end %>
我希望在没有几天的时候出现不同的消息。我怎么能这样做?
答案 0 :(得分:12)
您可以在for
理解之前或之后放置此内容:
<%= if Enum.empty?(@days) do %>
No days yet.
<% end %>