Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make :render => nothing work

I have an jquery AJAX call that loads a window. In the window, there is a form with a submit to allow the users to download an item. I have to make this second form use a regular submit so that I can prompt a download.
My problem is when there is no file to download, it redirects to the page in which this file is located.
I am trying many different styles of getting it to render nothing, but none of them seem to work.

unless params[:controller] == "reports"
  unless @jobs.present?
   flash.now[:error] = "No work orders for this selection."
   render :nothing => true
 end
end  

Also

respond_to do |format|
   format.html { render :nothing => true }
end

Nothing seems to work. Any ideas?

like image 972
Trip Avatar asked Apr 17 '12 13:04

Trip


1 Answers

Don't use render: nothing. This will "fail" ajax request. Instead, use:

render json: nil, status: :ok
like image 114
user3087881 Avatar answered Nov 01 '22 19:11

user3087881