Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put multiple lines of code into a format.html block?

My controller is

def destroy
@image.destroy
respond_to do |format|
  format.html
  format.json { render json: 'success' }
end

end

I want that request from html then it redirect to :back like

flash[:notice] = "Image Successfully deleted"
redirect_to :back

it works fine when I can't deal with json. I want to combine both of them so they send response accordingly to html or ajax request

like image 462
Haseeb Ahmad Avatar asked Feb 09 '23 19:02

Haseeb Ahmad


1 Answers

You can just put it inside the respond_to block for the html format

def destroy
  @image.destroy
  respond_to do |format|
    format.html do
      flash[:notice] = "Image Successfully deleted"
      redirect_to :back
    end
    format.json do
      render json: 'success'
    end
  end
end
like image 169
Patrick Oscity Avatar answered Feb 12 '23 10:02

Patrick Oscity