无法正确呈现轨道关联中的编辑和删除按钮



我在轨道上有两个脚手架。第一个是项目,第二个是阶段。项目与舞台有一对多关联。我正在project#show表中渲染项目及其阶段,每当我单击编辑阶段按钮时,总是渲染和更新第一阶段编辑页面。我希望在用户单击舞台编辑时编辑当前阶段。

stages_controller.rb

def edit
@stage = Stage.find(params[:project_id])
@project = Project.find(params[:project_id])
end
def update
respond_to do |format|
if @stage.update(stage_params)
format.html { redirect_to project_path(@project), notice: 'Stage was successfully updated.' }
format.json { render :show, status: :ok, location: @stage }
else
format.html { render :edit }
format.json { render json: @stage.errors, status: :unprocessable_entity }
end
end
end

projects_controller.rb

def show
@project = Project.includes({stages: {tasks: :sub_tasks}}).find(params[:id])
@stages = @project.stages
end

路线.rb

resources :projects do
resources :stages do
resources :tasks do
resources :sub_tasks
end
end
end

项目展示.html.erb

<tbody>
<% @stages.each do |stage| %>
<tr class="stage">
<td><%= stage.stage %></td>
<td><%= stage.planned_start_date.strftime("%d-%m-%Y") %></td>
<td><%= stage.planned_end_date.strftime("%d-%m-%Y") %></td>
<td><%= link_to "Add Task", new_project_stage_url(@project, stage), :class=>"button primary small" %></td>
<td><%= link_to 'Edit', edit_project_stage_path(@project), :class=>"button secondary small" %></td>
<td><%# link_to 'Destroy', stage, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% stage.tasks.each do |task| %>
<tr>
<td class="text-center"><%= task.task_name %></td>
<td><%= task.planned_start_date.strftime("%d-%m-%Y") %></td>
<td><%= task.planned_end_date.strftime("%d-%m-%Y") %></td>
<td><%= link_to "Add Sub Task", new_project_stage_task_sub_task_url(@project, stage, task), :class=>"button primary small" %></td>
<td><%# link_to 'Edit', edit_task_path(task) %></td>
<td><%# link_to 'Destroy', task, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
</tbody>

stages_controller.rb

def edit
@project = Project.find(params[:project_id])
end

最新更新