html - 如果登录为真,如何隐藏另一个 html 按钮?

标签 html css ruby-on-rails ruby ruby-on-rails-4

这里有两个按钮选项卡: 如何表达

1:

<% if logged_in? %>然后隐藏 b 按钮标签

2:

<% if studentlogged_in? %>然后隐藏A按钮标签

两种方法 <% 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 %>

最佳答案

也许你的意思是这个结构:

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

哪里显示学生版、普通版或什么都不显示,但绝不会同时显示两者。

关于html - 如果登录为真,如何隐藏另一个 html 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43334869/

相关文章:

javascript - 在滚动视口(viewport)中按顺序动画元素

javascript - 如何使用 React 创建自动增长-收缩输入?

javascript - 如何根据屏幕宽度在 Rails App 中编辑 TinyMCE 编辑器的宽度

ruby-on-rails - 在 RoR 中将参数传递给 CanCan

mysql - 保存在 MySQL 数据库中的 JSON 或 XML 或序列化数组

jquery - 在html中单击输入时的工具提示问题

javascript - jquery,javascript 在 Bootstrap 中不工作

html - 子菜单悬停显示限制

html - CSS 将颜色从灰色更改为 #330000

html - CSS:可变图像(横向/纵向)不同尺寸..需要在 div 容器中居中