Rails render head vs. status
Asked Answered
C

2

34

What's the difference between render head :ok vs. render status :ok in Rails? They both get returned as the header right?

Cassilda answered 28/10, 2017 at 23:28 Comment(0)
A
50

There is no difference really. The Rails doc says this about head:

The head method can be used to send responses with only headers to the browser. The head method accepts a number or symbol (see reference table) representing an HTTP status code

head :ok sets render to return just the header with status 200.

It's merely a shorthand for render nothing: true, status: :ok.

Rails 5 will also do head :no_content by default when you don't have a template defined for an action

Atiptoe answered 29/10, 2017 at 0:5 Comment(2)
so render status :ok is more versatile because it can be used as an option too right?Cassilda
I would say more verbose.Atiptoe
U
1

The answer used to work for me, but I tried it recently and got a no template error. This is what I use now

render plain: :success

It does not answer the question, but the answers don't work.

Usable answered 5/8, 2022 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.