Working through a very basic Sinatra web app, can’t get all the HTML code to show in browser

42 Views Asked by At

I’m working on a Sinatra app. Part of the code will show up in the browser while the other part will not and I can’t figure out why.

<h1>Welcome <%[email protected]%>!</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> and <h2> at the top of the page show in the browser but nothing else will.

1

There are 1 best solutions below

0
froderik On

You are checking if @user.clients is empty. But you are looping over @clients. Chance is that they do not have the same content. You should loop over the same variable as you use in your if statement.