简体   繁体   English

如何使用Twitter Bootstrap在Rails 3.2中实现切换丸?

[英]How do I implement toggle pills in Rails 3.2 with Twitter Bootstrap?

I took out this snippet to explain my issue. 我拿出这个片段来解释我的问题。

<ul class="nav nav-pills nav-stacked red"> 
    <li><%= link_to "Home",   'http://localhost:3000/home' %></li>
    <li><%= link_to "About",   'http://localhost:3000/about', :data => {:toggle=>"pill"} %></li>
</ul>

If I click on "Home", the link brings me to 'http://localhost:3000/home'. 如果我点击“主页”,链接会将我带到'http:// localhost:3000 / home'。 If I click on about, the pill toggles but the link does not work. 如果我点击约,药丸切换,但链接不起作用。 This is the resulting html: 这是由此产生的html:

<ul class="nav nav-pills nav-stacked red">
    <li><a href="http://localhost:3000/home">Home</a></li>
    <li><a href="http://localhost:3000/about" data-toggle="pill">About</a></li>
</ul>

My goal is to be able to click a link, go to the address and have the corresponding pill highlighted. 我的目标是能够点击链接,转到地址并突出显示相应的药丸。

I saw the tip about data-toggle="pill" here: http://twitter.github.com/bootstrap/javascript.html#tabs 我在这里看到了关于data-toggle =“pill”的提示: http//twitter.github.com/bootstrap/javascript.html#tabs

Thanks for the help! 谢谢您的帮助!

I think that doesn't work that way... the data-toggle in the example you provided has an anchor link (#about) and yours redirects to another page. 我认为这不起作用...你提供的示例中的数据切换有一个锚链接(#about),你的重定向到另一个页面。 You should do that server side or use an anchor link. 您应该执行该服务器端或使用锚链接。

Ran into same issue, and did some more experiments. 遇到同样的问题,做了一些实验。 From my results, to use external links you will need to remove "data-toggle" attribute, as following: 从我的结果来看,要使用外部链接,您需要删除“data-toggle”属性,如下所示:

<ul class="nav nav-pills nav-stacked red"> 
    <li><%= link_to "Home",   'http://localhost:3000/home' %></li>
    <li><%= link_to "About",   'http://localhost:3000/about' %></li>
</ul>


<ul class="nav nav-pills nav-stacked red">
    <li><a href="http://localhost:3000/home">Home</a></li>
    <li><a href="http://localhost:3000/about">About</a></li>
</ul>

I wound up doing a check if the current page was active 如果当前页面处于活动状态,我最后会检查一下

<li class="<%= 'active' if current_page?(root_path) %>">
    <%=link_to root_path do %>
        <i class="icon-white icon-home"></i>
        Home
    <% end %>
</li>  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM