ActionController::UnknownFormat (ActionController::UnknownFormat): 销毁
ActionController::UnknownFormat (ActionController::UnknownFormat): on destroy
我正在尝试销毁记录,我有 3 个用于列出记录的菜单。所以在销毁记录后,它应该重定向到我点击销毁方法的相同菜单。
但是当我尝试时,我得到了这个错误。
ActionController::UnknownFormat (ActionController::UnknownFormat): app/controllers/my_controller.rb:56:in `destroy'
删除link
<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
在 respond_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
我正在尝试销毁记录,我有 3 个用于列出记录的菜单。所以在销毁记录后,它应该重定向到我点击销毁方法的相同菜单。
但是当我尝试时,我得到了这个错误。
ActionController::UnknownFormat (ActionController::UnknownFormat): app/controllers/my_controller.rb:56:in `destroy'
删除link
<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
在 respond_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