Rails

Retrieve IP Address and User Agent with Ahoy in Rails

A memo about how to retrieve IP addresses and user agents with Ahoy in Rails. You can obtain information about the client, such as IP addresses and user agents accessing Rails. The model names are <code>Ahoy::Visit</code> and <code>Ahoy::Event</code>[8] pry(main)&gt; Ahoy::Visit.all[0].ip…

Shou Arisaka
1 min read
Sep 28, 2025

A memo about how to retrieve IP addresses and user agents with Ahoy in Rails. You can obtain information about the client, such as IP addresses and user agents accessing Rails.

The model names are Ahoy::Visit and Ahoy::Event

[8] pry(main)> Ahoy::Visit.all[0].ip
Ahoy::Visit Load (1.4ms)  SELECT "ahoy_visits".* FROM "ahoy_visits"
=> "10.0.2.2"

Share this article

Shou Arisaka Sep 28, 2025

🔗 Copy Links