active_model_serializers
active_model_serializers copied to clipboard
NoMethodError: undefined method `model_name' for Hash:Class
ActiveModelSerializers.config.adapter = :json
instead of using a serializer, for error_messages we do something like this
def render_error(resource, status = :unprocessable_entity)
render json: { errors: resource.errors.full_messages } , status: status
end
or sometimes we simply do
render json: {status: "approved"}
all of those throw the error ' undefined method `model_name' for Hash:Class' i can't find a workaround to bypass serializer lookup for certain actions.
how to workaround this? what are we doing wrong?
This same question was asked in https://github.com/rails-api/active_model_serializers/issues/2133
You can set the root key by following the guides here: https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/serializers.md#root
If you are looking to disable serializer lookup entirely, you can see the docs here: https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/configuration_options.md#serializer_lookup_enabled