Sourabh Banka
Sourabh Banka

Reputation: 1117

How to get current_sign_in_ip in rails

I am using rails for the backend and react for the frontend. I am using rails api only.

I would like to store the current_sign_in_ip for every user. I am not using devise. How can I achive it.

Upvotes: 1

Views: 274

Answers (3)

Alex Kojin
Alex Kojin

Reputation: 5204

You can get IP in a controller by calling request.remote_ip

Upvotes: 1

Hardik Upadhyay
Hardik Upadhyay

Reputation: 2659

This will work as well.

request.ip

EDIT

request.ip is ip detection method provided by Rack::Request. It looks at the HTTP_X_FORWARDED_FOR header and picks the last one from the list.

source

Upvotes: 1

RahulOnRails
RahulOnRails

Reputation: 6542

request.remote_ip

request.remote_ip is an interpretation of all the available IP address information and it will make a best-guess. If you access the variables directly you assume responsibility for testing them in the correct precedence order. Proxies introduce a number of headers that create environment variables with different names.

Upvotes: 1

Related Questions