I have a controller which is working fine for every method but an update method which needs to return the edited contents of a record so that the updated datetime and which user edited the record can be used by the requesting application. Instead of returning this data however it returns a blank string.
If I manually render some JSON it works fine. In this same controller I have a create method and a show method which both use the representer and that returns data as expected.
def update
if credential.save
consume! credential, represent_with: App::Configuration::CredentialRepresenter
respond_with credential, represent_with: App::Configuration::CredentialRepresenter
else
render json: { error: credential.errors.full_messages.to_sentence }, status: :unprocessable_entity
end
end
The data comes through just fine as it is in the code above with a standard JSON render. Using the representer results in a blank string being sent. The only real difference between this update method and the create and show methods where the representer works as expected is that consume! is called before the save method, which should not make a difference. Obviously I can't derive the updated datetime until it's saved and the values I need are present in the model because I can send them with a standard json render.
Under what conditions would a representer render a blank string like this?
I have a controller which is working fine for every method but an update method which needs to return the edited contents of a record so that the updated datetime and which user edited the record can be used by the requesting application. Instead of returning this data however it returns a blank string.
If I manually render some JSON it works fine. In this same controller I have a
create
method and ashow
method which both use the representer and that returns data as expected.if instead I send data this way
The data comes through just fine as it is in the code above with a standard JSON render. Using the representer results in a blank string being sent. The only real difference between this
update
method and thecreate
andshow
methods where the representer works as expected is that consume! is called before the save method, which should not make a difference. Obviously I can't derive the updated datetime until it's saved and the values I need are present in the model because I can send them with a standard json render.Under what conditions would a representer render a blank string like this?