我正在嘗試銷毀記錄,我有 3 個用于列出記錄的選單。所以在銷毀記錄后,它應該重定向到我單擊銷毀方法的相同選單。
但是當我嘗試時,我收到了這個錯誤。
ActionController::UnknownFormat (ActionController::UnknownFormat): app/controllers/my_controller.rb:56:in `destroy'
洗掉鏈接
<a href="<%=my_path(data,:page_name=>params[:action])%>" class="btn"" data-placement="bottom" title="Delete" data-method="delete" data-confirm="Are you sure?">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</a>
銷毀方法
def destroy
@page.destroy
respond_to do |format|
if params[:page_name] == "first"
format.html { redirect_to first_home_index_path, notice: 'Url was successfully destroyed.' }
elsif params[:page_name] == "second"
format.html { redirect_to second_home_index_path, notice: 'Url was successfully destroyed.' }
elsif params[:page_name] == "third"
format.html { redirect_to third_home_index_path, notice: 'Url was successfully destroyed.' }
end
format.json { head :no_content }
end
end
uj5u.com熱心網友回復:
添加條件 inrespond_to應該發生在format塊內部,而不是外部。
def destroy
@page.destroy
respond_to do |format|
format.html do
if params[:page_name] == "first"
redirect_to first_home_index_path, notice: 'Url was successfully destroyed.'
elsif ....
end
end
format.json { head :no_content }
end
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/380873.html
上一篇:Rails有很多通過有一個多型
