active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

NoMethodError: undefined method `model_name' for Hash:Class

Open krtschmr opened this issue 8 years ago • 1 comments
trafficstars

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?

krtschmr avatar May 23 '17 07:05 krtschmr

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

cassidycodes avatar May 23 '17 13:05 cassidycodes