如何在link_to中包装列表项?

时间:2015-01-26 02:34:53

标签: css ruby-on-rails ruby

目前,只有文本是可点击的,并且将用户带到应用程序中的指定路径,而点击li下拉列表的任何其他部分都不会产生任何结果。

以下是代码:

<li id='dropdown'>
    <%= current_user.email %> ▾
        <ul id='dropdown-list'>
             <li> <%= link_to "My Account", current_user %> </li>
            <li><%= link_to "Log Out", session_path("current"), method: :delete %></li>
        </ul>
</li>

这是css:

#dropdown-list {
  padding: 0;
  position: absolute;
  top: 48px;
  width: 150px;
  -webkit-box-shadow: none;
  -moz-box-shadow: none;
  box-shadow: 0px 2px 5px #bcbfc3;
  display: block;
  opacity: 0;
  visibility: hidden;
  -webkit-transiton: opacity 0.2s;
  -moz-transition: opacity 0.2s;
  -ms-transition: opacity 0.2s;
  -o-transition: opacity 0.2s;
  -transition: opacity 0.2s;
}

#dropdown-list li { 
  background: #fff; 
  display: block; 
  color: #7D818A;
}
#dropdown-list li:hover{
 background-color: #ECECEE; 
}

#dropdown:hover ul {
  display: block;
  opacity: 1;
  visibility: visible;
}

2 个答案:

答案 0 :(得分:2)

您可以通过创建这样的块来包装link_to

<%= link_to(current_user) do %>
...stuff to wrap here...
<%=end%>

我想你可能想要这样的东西:

<li id='dropdown'>
    <%= current_user.email %> ▾
        <ul id='dropdown-list'>
          <%= link_to(current_user) do %>
             <li>My Account</li>
          <%= end %>
            <li><%= link_to "Log Out", session_path("current"), method: :delete %></li>
        </ul>
</li>

答案 1 :(得分:1)

CSS解决方案:

#dropdown-list>li>a{
  display: block;
}