2017-04-11 76 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