带锚和制表符的redirect_to

时间:2014-12-29 21:13:33

标签: html ruby-on-rails twitter-bootstrap

我正在尝试使用重定向将用户发送回他们刚刚访问的标签,Redemptions,并使用锚点将此标签显示在视图中。为了澄清我希望第二个或“最后”选项卡在重定向时打开。问题是如何实现这一目标?

class CustomerRewardRedemptionsController
  def fulfill
    redirect_to admin_customer_rewards_path
  end
end

可以是redirect_to:back

<div class="tab-nav">
  <ul class="tabs tabs-large">
    <li class="active"><a href="#points-leveling" data-toggle="tab">Points Leveling</a><b class="triangle"></b></li>
    <li class="last"><a href="#leaderboard" data-toggle="tab">Redemptions</a></li>
  </ul> 
</div>
<div class="tab-pane" id="leaderboard">
  <tr>
    <td><%= link_to 'Mark Fulfilled', fulfill_admin_customer_reward_redemptions_path(customer_reward_redemption_id: redemption.id), method: :put, class: 'btn', 'data-confirm' => 'Mark the redemption fulfilled?' %></td>
  </tr>
</div>

更新:锚点工作,标签仍然打开默认值,而不是“最后一个”。

redirect_to admin_customer_rewards_path + "#rewards"

此加上将以下锚点添加到“tab-nav”

之上一级
<div class="col-md-12"><a name="rewards"></a>
  <div class="tab-nav">
    <ul class="tabs tabs-large">
      <li class="active"><a href="#points-leveling" data-toggle="tab">Points Leveling</a><b class="triangle"></b></li>
      <li class="last"><a href="#leaderboard" data-toggle="tab">Redemptions</a></li>
    </ul> 
  </div>
  <div class="tab-pane" id="leaderboard">
    <tr>
      <td><%= link_to 'Mark Fulfilled', fulfill_admin_customer_reward_redemptions_path(customer_reward_redemption_id: redemption.id), method: :put, class: 'btn', 'data-confirm' => 'Mark the redemption fulfilled?' %></td>
    </tr>
  </div>
</div>

解决方案:找到此解决方案https://stackoverflow.com/a/18370966/3889146

<div class="col-md-12"><a name="rewards"></a>
  <div class="tab-nav">
    <ul class="tabs tabs-large">
      <li class="<%= @tab == "rewards" ? "active" : "" %>"><a href="#points-leveling" data-toggle="tab">Points Leveling</a><b class="<%= @tab == "rewards" ? "triangle" : "" %>"></b></li>
      <li class="last <%= @tab == "rewards" ? "" : "active" %>"><a href="#leaderboard" data-toggle="tab">Redemptions</a><b class="<%= @tab == "rewards" ? "" : "triangle" %>"></b></li>
    </ul> 
  </div>
  <div class="tab-pane <%= @tab == "rewards" ? "active" : "" %>" id="points-leveling">
  </div>
  <div class="tab-pane <%= @tab == "rewards" ? "" : "active" %>" id="leaderboard">
    <tr>
      <td><%= link_to 'Mark Fulfilled', fulfill_admin_customer_reward_redemptions_path(customer_reward_redemption_id: redemption.id), method: :put, class: 'btn', 'data-confirm' => 'Mark the redemption fulfilled?' %></td>
    </tr>
  </div>
</div>

使用上述答案和https://stackoverflow.com/a/757937/3889146

解决了redirect_to问题
class CustomerRewardRedemptionsController
  def index
    @tab = params[:tab]
  end

  def fulfill
    redirect_to admin_customer_rewards_path(tab: "rewards") + "#rewards"
  end
end

希望这有助于其他人!

0 个答案:

没有答案