What's the difference between render head :ok
vs. render status :ok
in Rails? They both get returned as the header right?
Asked
Active
Viewed 2.4k times
33

stackjlei
- 9,485
- 18
- 65
- 113
2 Answers
48
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

Cyzanfar
- 6,997
- 9
- 43
- 81
-
3so `render status :ok` is more versatile because it can be used as an option too right? – stackjlei Oct 29 '17 at 01:13
-
4I would say more verbose. – Cyzanfar Oct 29 '17 at 01:19
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.

oky_sabeni
- 7,672
- 15
- 65
- 89