![](/img/trans.png)
[英]ActionController::UnknownFormat (ActionController::UnknownFormat)
[英]ActionController::UnknownFormat (ActionController::UnknownFormat): on destroy
我正在尝试销毁记录,我有 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
在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.