Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails render template with status

What is the simplest/shortest way to respond in an API controller. Currently the following works:

respond_to do |format|
  format.json { render 'client', status: :ok }
end

however this controller will only ever respond to json (respond_to :json) so the whole respond_to do |format| thing seems like unnecessary code.

Ideally I would just like to do something simple like:

render 'client', status: :ok

Update: I neglected to mention that: 'client' is a jbuilder template that does not match my action name.

like image 331
TrevTheDev Avatar asked Sep 15 '25 03:09

TrevTheDev


1 Answers

You can use render directly

render json: 'client', status: :ok
like image 177
Hass Avatar answered Sep 16 '25 15:09

Hass