0
我有一個work_histories的窗體。當用戶刪除工作記錄時,我希望他們被重定向到他們的用戶個人資料頁面,而不是調用此控制器操作的user_work_histories_url(work_histories#show)。我想重定向到user_path(@user)的用戶個人資料頁面。導軌將用戶重定向到配置文件頁面後,銷燬操作
我試着改變work_histories銷燬操作重定向到user_path(@user)而不是user_work_histories_url,但它說我剛剛刪除的作業的id找不到。
,這裏是我的work_histories
# DELETE /users/:user_id/work_histories/:id
def destroy
@work_history = WorkHistory.find(params[:id])
@work_history.destroy
respond_to do |format|
format.html { redirect_to user_work_histories_url,
notice: "The work history for your #{@work_history.job_title.upcase} job was successfully destroyed." }
format.json { head :no_content }
end
end
這裏控制器是爲work_histories
<p id="notice"><%= notice %></p>
<p>
<strong>Job Title:</strong>
<%= @work_history.job_title %>
</p>
<p>
<strong>Job Description:</strong>
<%= @work_history.description %>
</p>
<%= link_to 'Back', user_work_histories_path(@user) %> |
<%= link_to 'Edit', edit_user_work_history_path(@user, @work_history) %> |
<%= link_to 'Delete', user_work_history_path(@user, @work_history), method: :delete,
data: { confirm: 'Are you sure you want to delete this work history?' } %>
你保持通知消息,當您更改URL?也許你應該在刪除記錄之前創建通知消息。 – Smek