I'm rescuing an unauthorized exception, and want to render an alert within this rescue block. Since this is in my application controller, this rescue could be hit in multiple formats, so I need a respond_to
block.
If I do this without a respond_to
, everything works fine. The status is set to 401, and I see the proper exception message flashed.
render :json => exception.message, :status => 401
However, if I do the same thing inside a repond_to
block, nothing works. Status doesn't get set, and the exception message doesn't get rendered.
respond_to do |format|
format.json { render :json => exception.message, :status => 401 }
end
What could be the problem here? I've looked through a ton of examples, and this seems like it should work, but the status and message seem to be ignored.