Reputation: 9700
I have a Rails action which responds with head :ok
, rather than rendering any content. I'm calling this action using RestClient, like so:
resp = RestClient.post("#{api_server_url}/action/path", {:param_1 => thing, :param_2 => other_thing}, :authorization => auth)
The Rails server log shows that this worked as expected:
Completed 200 OK in 78ms (ActiveRecord: 21.3ms)
However, the resulting value of resp
is the string " "
, rather than an object I can examine (to see what its status code is, for instance).
I tried changing the action to use head :created
instead, just to see if it produced a different result, but it's the same: " "
.
How can I get the status code of this response?
Upvotes: 2
Views: 854
Reputation: 5019
RestClient.post returns an instance of the class RestClient::Response that inherits from the String class.
You can still check the return code by calling the method code resp.code
. Other methods are for example resp.headers
and resp.cookies
.
Upvotes: 3