3

如何将重定向更改为特定页面上的特定 Twitter Bootstrap选项卡?就像是:

def destroy
  @custom_article = CustomArticle.find(params[:id])
  @custom_article.destroy
  respond_to do |format|
    format.html { redirect_to documents_url[#specific_tab_here?] }
    format.json { head :no_content }
  end
end

谢谢!

更新

请参阅 @PeterWong 和 @emm 的答案组合以获得解决方案。

4

4 回答 4

6

这一点 JS 为我修复了它:

$(function(){
  var hash = window.location.hash;
  hash && $('ul.nav a[href="' + hash + '"]').tab('show');
});

它对 turbolinks 做了一些奇怪的事情,但由于这都是基于重定向的,所以这不是问题。

于 2013-08-22T05:10:16.560 回答
4

在您的控制器中:

def destroy
  redirect_to documents_url(tab: "specific_tab")
end

文档控制器:

class DocumentsController < ApplicationController

  def index
    @tab = params[:tab]
  end
end

在 html 中:

<div class="tab-pane <%= @tab == "specific_tab" ? "active" : "" %>">
于 2013-08-22T02:56:49.307 回答
1

使用代码对 @emm 解决方案进行小调整,以使用 turbolinks:

var ready;

ready = function() {
  var hash = window.location.hash;
  hash && $('ul.nav a[href="' + hash + '"]').tab('show');
};

$(document).ready(ready);
$(document).on('page:load', ready);
于 2015-01-03T00:39:59.500 回答
1

这个怎么样?

redirect_to "#{documents_url}#specific_tab"
于 2013-08-22T02:25:48.587 回答