Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

representer returns blank string #137

Open
hammer65 opened this issue Aug 28, 2019 · 0 comments
Open

representer returns blank string #137

hammer65 opened this issue Aug 28, 2019 · 0 comments

Comments

@hammer65
Copy link

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

if instead I send data this way

if credential.save
      render json: {
        modifiedBy: credential.modified_by,
        updatedAt: credential.updated_at
      }
else

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant