Ruby-on-rails – How to make :render => nothing work

ruby-on-rails

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?

Best Solution

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

render json: nil, status: :ok