0

我正在开发一个 Sinatra 应用程序。部分代码将显示在浏览器中,而另一部分则不会,我不知道为什么。

<h1>Welcome <%=@user.username%>!</h1>
<h2>Your Clients:</h2>

<%if @user.clients.empty?%>
  <h3> You have no clients. Add a client using the link below.</h3>
  <h2><a href="/clients/new">Add Client</a></h2>

<% else %>
  <% @clients.each do |client| %>
    <ul>
      <li><a href="/clients/<%=client.id%>"><%= client.name %></a></li>
    </ul>
  <% end %>
<% end %>

<h1><h2>在页面顶部显示在浏览器中,但没有其他内容。

4

1 回答 1

0

您正在检查是否@user.clients为空。但是你正在循环@clients。机会是它们没有相同的内容。您应该循环使用与 if 语句中相同的变量。

于 2018-02-02T07:28:35.010 回答