title: Rails 5.1 how to render no content response in format.json
body: <p>I have looked at at least 10 questions on this and tried everything (eg. like <a href="https://stackoverflow.com/questions/43428991/what-to-use-instead-of-render-text-and-render-nothing-true-in-rails-5-1">this question</a>), but none of the suggestions work, eg:</p>
  
  <p>This for example:</p>
  
  <pre><code>format.json head :no_content and return
  </code></pre>
  
  <p>throws this error:</p>
  
  <pre><code>ArgumentError (wrong number of arguments (given 2, expected 1)):
  </code></pre>
  
  <p>Whilst this:</p>
  
  <pre><code>format.json head and return
  </code></pre>
  
  <p>throws this error:</p>
  
  <pre><code>ArgumentError (wrong number of arguments (given 0, expected 1..2)):
  </code></pre>
  
  <p>This is what I currently have in the controller action:</p>
  
  <pre><code>def paid
      @user = User.find_by(id: session['user_id'])
      respond_to do |format|    
        if !@user.nil?
          @user.is_paid = true
          @user.payment_reference = payment_params[:reference]
          @user.save
          format.json { render head, status: :no_content } and return
        else
          format.json render json: { message: "failed to record payment" }, status: :unprocessable_entity
        end
      end
    end
  </code></pre>
  
  <p>This works but in the console throw an error:</p>
  
  <pre><code>No template found for PaymentsController#paid, rendering head :no_content
  </code></pre>
  
  <p>I don't want to add an empty template to solve this. I want to tell Rails that I want to render head :no_content!</p>
  
  <p><a href="https://stackoverflow.com/questions/14716151/why-does-rails-want-to-return-head-no-content-for-json-put-requests">This question</a> shows that in Rails 3.1 the default generated code did this:</p>
  
  <pre><code>format.json { head :no_content }
  </code></pre>
  
  <p>but that shows the same exact error in the log.</p>