Rails 3.2.3 + Twitter Bootstrap + Nav-Tabs:如何显示特定的标签? [英] Rails 3.2.3 + Twitter Bootstrap + Nav-Tabs: How to show a specific tab?

查看:92
本文介绍了Rails 3.2.3 + Twitter Bootstrap + Nav-Tabs:如何显示特定的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个关于rails和bootstrap的新手问题.

another newbie-question regarding rails and bootstrap.

我正在使用类似这样的东西:

I am using something like this:

<div class="tabbable tabs-left">
<ul class="nav nav-tabs">
    <li class="active"><a href="#tab1" data-toggle="tab">About us</a></li>
            <li><a href="#tab9" data-toggle="tab">Address</a></li>
</ul>
<div class="tab-content">
    <div class="tab-pane active" id="tab1">
        <%= render 'about_us' %>
    </div>
    <div class="tab-pane" id="tab9">
        <%= render 'address' %>
    </div>
</div>

我的问题是我渲染了包含表格的地址".通过提交此表格,我最终进入了另一个控制器.使用此控制器保存新地址后,我想重定向到此页面并显示地址标签.

My problem is that I render 'address' which includes a form. By submitting this form I end up in an different controller. After saving a new address with this controller I would like to redirect to this page and show the address tab.

我尝试过的重定向命令是:redirect_to salon_path(@ salon.id.to_s +#tab9") 这导致调用url .../salons/1%23tab9.我认为我需要它的.../沙龙/1#tab9.

The redirect command I tried was: redirect_to salon_path(@salon.id.to_s + "#tab9") This results in calling the url .../salons/1%23tab9. What I think I need its .../salons/1#tab9.

但是也许您有一个更好的解决方案,如何选择一个特定的标签.

But maybe you are having a better solution how to choose one specific tab.

使用:

gem 'rails', '3.2.3'
gem 'bootstrap-sass', '2.0.3'.

推荐答案

我自己可以弄清楚,这篇文章将我带到正确的轨道上:

I could figure it out myself, this post here brought me onto the right track: How to get Twitter-Bootstrap navigation to show active link?

<div class="tabbable tabs-left">
<ul class="nav nav-tabs">
    <li class="<%= 'active' if params[:tab] == 'tab1' %>"><a href="#tab1" data-toggle="tab">About us</a></li>
    <li class="<%= 'active' if params[:tab] == 'tab9' %>"> <a href="#tab9" data-toggle="tab">Address</a></li>
</ul>

<div class="tab-content">
    <div class="<%= if (params[:tab] == 'tab1' || !params[:tab])then 'tab-pane active'  else 'tab-pane' end%>" id="tab1">
        <%= render 'about_us' %>
    </div>
    <div class="<%= if params[:tab] == 'tab9' then 'tab-pane active'  else 'tab-pane' end%>" id="tab9">
        <%= render 'address' %>
    </div>
</div>

在我的示例中,我这样称呼它:

And in my example I call it like this:

redirect_to salon_path(@salon.id, tab:"tab9")

这篇关于Rails 3.2.3 + Twitter Bootstrap + Nav-Tabs:如何显示特定的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆