Home > Enterprise >  ActionController::UnknownFormat (ActionController::UnknownFormat): on destroy
ActionController::UnknownFormat (ActionController::UnknownFormat): on destroy

Time:12-11

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])%>" " data-placement="bottom" title="Delete" data-method="delete" data-confirm="Are you sure?">
  <i  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

CodePudding user response:

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
  • Related