I'm trying to use redirect to send the user back to the tab they were just at, Redemptions, and use an anchor to bring this tab into view. To clarify I want the second, or "last" tab to open upon redirect. The question is how do I make this happen?
class CustomerRewardRedemptionsController
def fulfill
redirect_to admin_customer_rewards_path
end
end
Could be 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>
Update: The anchor works, tab still opens the default and not the "last".
redirect_to admin_customer_rewards_path + "#rewards"
This plus adding the below anchor one level up above the "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>
Solution: Found this solution 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>
Solved the redirect_to with the above answer and https://stackoverflow.com/a/757937/3889146
class CustomerRewardRedemptionsController
def index
@tab = params[:tab]
end
def fulfill
redirect_to admin_customer_rewards_path(tab: "rewards") + "#rewards"
end
end
Hope this helps others!