Rack middleware to get client IP address on Heroku, extracted from our API service.
Add this line to your application's Gemfile:
gem 'real_ip', github: 'quipper/real_ip'
And then execute:
$ bundle
Or install it yourself as:
$ gem install real_ip
- Mount
RealIp
rack middleware at the top of your Rack application's middleware stack.
Rack (config.ru
)
require 'real_ip'
use RealIp
Rails (config/application.rb
or config/environments/*.rb
)
module MyApp
class Application < Rails::Application
config.middleware.insert 0, 'RealIp'
end
end
MyApp::Application.configure do
config.middleware.insert 0, 'RealIp'
end
- On your controller, use
request.env['QUIPPER_REMOTE_ADDR']
to get the IP address
- Fork it ( https://github.com/[my-github-username]/real_ip/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request