0

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 <%=@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> and <h2> at the top of the page show in the browser but nothing else will.

froderik
  • 4,642
  • 3
  • 33
  • 43
Ryo123
  • 1
  • 1
    If you View Source on your page (Ctrl+U), what HTML shows up? Note that `@user.clients` and `@clients` are different, so it may be that the `else` is reached but no `
      `s are rendered.
    – Ry- Jan 24 '18 at 02:04
  • only the

    and

    show up on the Source code for HTML

    – Ryo123 Jan 24 '18 at 18:37
  • So… did you mean `@user.clients`? – Ry- Jan 24 '18 at 22:25

1 Answers1

0

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.

froderik
  • 4,642
  • 3
  • 33
  • 43