我有3个模型,其中员工has_many保险和员工has_many教育和保险和教育belongs_to员工。如何留在同一页上,当我点击侧栏链接在Rails
整个流程工作正常。
现在我有一个要求,当我点击员工 - >编辑时,我必须在保险和教育链接的编辑表单下显示一个侧栏。当我点击保险/教育时,它应该在同一个编辑页面中呈现。
员工/ edit.html.erb
<h1>
<%= @employee.full_name %>
</h1>
<div class="tabpanel">
<div class="tab-content">
<div class="tab-pane active" id="home" role="tabpanel">
<%= render 'form' %>
</div>
</div>
</div>
<%= render 'layouts/sidebar' %>
布局/ _sidebar.html.erb
<div class="sidebar">
<ul class="nav">
<li>
<%= link_to image_tag("Insurances.png")+"Insurances", employee_insurances_path(@employee) %>
</li>
<li>
<%= link_to image_tag("Education.png")+"Education", employee_educations_path(@employee) %>
</li>
</ul>
</div>
我的保险控制器
class InsurancesController < ApplicationController
before_action :set_insurance, only: [:show, :edit, :update, :destroy]
respond_to :html
def index
@employee = Employee.find(params[:employee_id])
@insurances = @employee.insurances.all
respond_with(@insurances)
end
def show
@employee = Employee.find(params[:employee_id])
respond_with(@insurance)
end
def new
@employee = Employee.find(params[:employee_id])
@insurance = @employee.insurances.build
end
def edit
@employee = Employee.find(params[:employee_id])
end
def create
@employee = Employee.find(params[:employee_id])
@insurance = @employee.insurances.create(insurance_params)
redirect_to employee_path(@employee)
end
def update
@employee = Employee.find(params[:employee_id])
@insurance.update(insurance_params)
redirect_to employee_path(@employee)
end
def destroy
@employee = Employee.find(params[:employee_id])
@insurance.destroy
redirect_to employee_path(@employee)
end
private
def set_insurance
@insurance = Insurance.find(params[:id])
end
def insurance_params
params.require(:insurance).permit(:name_of_dependent, :relationship,:policy_numbere)
end
end
任何想法如何点击边栏链接时呈现相同的页面?