Robert
Robert

Reputation: 311

What is the point to have two <% if user_signed_in? %> for the code below?

Working on a Rails tutorial and don't understand why there are two <% if user_signed_in? %> as you can see in the code below. Why not have the code under a single <% if user_signed_in? %> ? I've tried putting them together and all which seems to change is the layout of the navbar, would that be the single purpose?

<ul class="nav navbar-nav">
  <li>
    <%= link_to "Sign Up", new_user_registration_path %>
  </li>
  <% if user_signed_in? %>
    <li>
      <%= link_to "Sign Out", destroy_user_session_path, method: :delete %>
    </li>
  <% else %>
    <li>
      <%= link_to "Log In", new_user_session_path, method: :delete %>
    </li>
  <% end %>
</ul>
<% if user_signed_in? %>
  <p>
    <%= link_to "New Message", new_message_path, class: "navbar-right navbar-text navbar-link" %>
  </p>
<% end %>

Upvotes: 1

Views: 60

Answers (1)

Yana Agun Siswanto
Yana Agun Siswanto

Reputation: 2032

It is because the author want to keep the <ul> element.

The <ul> element wont be rendered on the rendered html if the control statement is on the parent of <ul> and <p>

Upvotes: 1

Related Questions