I am trying to destroy a record, I have 3 menus for listing records. so after destroy of a record it should redirect to the same menu from where I have clicked destroy method.
But when I tried it I got this error.
ActionController::UnknownFormat (ActionController::UnknownFormat): app/controllers/my_controller.rb:56:in `destroy'
delete 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>
destroy method
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
Adding conditions in respond_to
should happen inside the format
block, not outside.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.