2017-04-11 67 views
-1

這裏有兩個按鈕標籤: 如何表達如果登錄爲真,如何隱藏另一個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 %> 

回答

1

也許你的意思是這樣的結構:

<% if studentlogged_in? %> 
    ... 
<% elsif logged_in? %> 
    ... 
<% end %> 

其中,顯示學生之一,經常一個,或什麼,但不可能兼顧。

+0

一個條件;如果沒有人登錄,BOOT按鈕標籤就會存在 – Vito

+0

只需將這兩個按鈕都移到最後的'else'子句中即可。 – tadman

0

我想這是你想要的東西:

<% if logged_in %> 
    # render partial containing html code for button A 
<% elsif studentlogged_in %> 
    # render partial containing html code for button B 
<% else %> 
    # render both partials 
<% end %> 
+0

他更快..... – Vito

+0

哈哈耶。儘管我們都在努力提供幫助,但這不是一場競賽 – amrrbakry