我正在使用Foundation-zurb选项卡功能,并从不同模型渲染数据。创建一些财务信息后,它将重定向到带有在基础类中定义的活动选项卡的显示页面。创建一些财务信息后,我如何重定向到财务标签?
project#show.html.erb
<div class="row">
<div class="columns">
<ul class="tabs" data-tabs id="example-tabs">
<li class="tabs-title is-active"><a href="#panel1" aria-selected="true">Project Activities</a></li>
<li class="tabs-title"><a href="#panel2">Project Financial</a></li>
</ul>
<div class="tabs-content" data-tabs-content="example-tabs">
<div class="tabs-panel is-active" id="panel1">
<%= render "projects/project_activities" %>
</div>
<div class="tabs-panel" id="panel2">
<%= render "financials/index" %>
</div>
financials_controller.rb
def create
@financial = @project.financials.build(financial_params)
respond_to do |format|
if @financial.save
format.html { redirect_to project_path(@project), notice: 'Financial was successfully created.' }
format.json { render :show, status: :created, location: @financial }
else
end
end
end
只需使用anchor
选项作为URL辅助程序
redirect_to project_path(@project, anchor: 'panel2')
您需要在选项卡上添加data-deep-link
选项以将当前状态存储在URL中,并允许用户在页面加载时使用带有哈希值的URL打开特定的选项卡
<ul class="tabs" data-tabs data-deep-link="true" id="example-tabs">
您可以在docs中找到更多有用的选项