這裏有兩個按鈕標籤: 如何表達如果登錄爲真,如何隱藏另一個html按鈕?
1:
<% if logged_in? %>
然後隱藏b按鈕標籤
2:
<% if studentlogged_in? %>
然後隱藏按鈕標籤
兩種方法<% if logged_in? %> , <% if studentlogged_in? %>
有效
<% if logged_in? %> <<==#A button tab
<li><%= link_to "Users", users_path %></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Tutor Center", login_path %></li>
<% end %>
<% if studentlogged_in? %> <<==#B button tab
<li><%= link_to "StudentUsers", student_users_path %></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", studentcurrent_user %></li>
<li>
<%= link_to "Settings", edit_user_path(studentcurrent_user) %>
</li>
<li class="divider"></li>
<li>
<%= link_to "Log out", studentlogout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Student Center", studentlogin_path %></li>
<% end %>
一個條件;如果沒有人登錄,BOOT按鈕標籤就會存在 – Vito
只需將這兩個按鈕都移到最後的'else'子句中即可。 – tadman