jsonapi-rails
jsonapi-rails copied to clipboard
Trying to render STI classes gives a cryptic error
trafficstars
Something similar was briefly mentioned here:
https://github.com/jsonapi-rb/jsonapi-rails/issues/68#issuecomment-417905177
When a relation contains an item of an STI type jsonapi-rails isn't able to infer the renderer for it and instead it only crashes with the error:
ActiveModel::UnknownAttributeError:
unknown attribute 'url_helpers' for PrimarySubject.
At the very least a helpful error message would go a long way here, as this is difficult to debug yourself.
The workaround is to manually specify all classes:
{
Subject: SerializableSubject,
PrimarySubject: SerializableSubject
SecondarySubject: SerializableSubject
ModernLanguagesSubject: SerializableSubject,
FurtherEducationSubject: SerializableSubject
}