Sha256: f6aed1ea81deb05a77446d9d8394d74090fad5839010b0397ce85be5f29bf945

Contents?: true

Size: 973 Bytes

Versions: 11

Compression:

Stored size: 973 Bytes

Contents

[Back to Guides](../README.md)

The ActiveModelSerializers grape formatter relies on the existence of `env['grape.request']` which is implemeted by `Grape::Middleware::Globals`. You can meet his dependency by calling it before mounting the endpoints.

In the simpliest way:

```
class API < Grape::API
  # @note Make sure this is above you're first +mount+
  use Grape::Middleware::Globals
end
```

or more like what is shown in current Grape tutorials:

```
module MyApi
  class ApiBase < Grape::API
    use Grape::Middleware::Globals

    require 'grape/active_model_serializers'
    include Grape::ActiveModelSerializers

    mount MyApi::V1::ApiBase
  end
end
```

You could meet this dependency with your own middleware. The invocation might look like:

```
module MyApi
  class ApiBase < Grape::API
    use My::Middleware::Thingamabob

    require 'grape/active_model_serializers'
    include Grape::ActiveModelSerializers

    mount MyApi::V1::ApiBase
  end
end
```

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
active_model_serializers_custom-0.10.90 docs/howto/grape_integration.md
active_model_serializers-0.10.9 docs/howto/grape_integration.md
active_model_serializers-0.10.8 docs/howto/grape_integration.md
active_model_serializers-0.10.7 docs/howto/grape_integration.md
active_model_serializers-0.10.6 docs/howto/grape_integration.md
active_model_serializers-0.10.5 docs/howto/grape_integration.md
active_model_serializers-0.10.4 docs/howto/grape_integration.md
agi_active_model_serializers-0.10.9 docs/howto/grape_integration.md
agi_active_model_serializers-0.10.8 docs/howto/grape_integration.md
agi_active_model_serializers-0.10.7 docs/howto/grape_integration.md
active_model_serializers-0.10.3 docs/howto/grape_integration.md