Skip to content

Commit

Permalink
Merge pull request #2183 from onurkucukkece/issue-2182
Browse files Browse the repository at this point in the history
Update readme about registering middleware in custom Rails applications
  • Loading branch information
dblock authored Aug 1, 2021
2 parents a20bcb1 + c5f0515 commit bd65726
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3642,6 +3642,14 @@ You can access the controller params, headers, and helpers through the context w
Note that when you're using Grape mounted on Rails you don't have to use Rails middleware because it's already included into your middleware stack.
You only have to implement the helpers to access the specific `env` variable.

If you are using a custom application that is inherited from `Rails::Application` and need to insert a new middleware among the ones initiated via Rails, you will need to register it manually in your custom application class.

```ruby
class Company::Application < Rails::Application
config.middleware.insert_before(Rack::Attack, Middleware::ApiLogger)
end
```

### Remote IP

By default you can access remote IP with `request.ip`. This is the remote IP address implemented by Rack. Sometimes it is desirable to get the remote IP [Rails-style](http://stackoverflow.com/questions/10997005/whats-the-difference-between-request-remote-ip-and-request-ip-in-rails) with `ActionDispatch::RemoteIp`.
Expand Down

0 comments on commit bd65726

Please sign in to comment.