Quando firmo nell'applicazione, il codice qui sotto viene chiamato. Così all'interno del SessionsController, tavolo SignupHistory viene popolata con il .createmetodo.
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
helper_method :current_user
before_action :set_timezone, :current_country
def current_country
if session[:ip_country_code].present?
return @current_country = session[:ip_country_code]
end
use_default = request.location.nil? || request.location.country_code.blank? || request.location.country_code == 'RD'
country_code = use_default ? ENV['DEFAULT_IP_COUNTRY_CODE'] : request.location.country_code
@current_country = session[:ip_country_code] = country_code
end
end
sessions_controller.rb
class SessionsController < ApplicationController
def save_signup_history(member_id)
SignupHistory.create(
member_id: member_id,
ip: request.ip,
accept_language: request.headers[Accept-Language],
ua: request.headers[User-Agent],
login_location: request.location
)
end
end
attributi del database
Tuttavia, invece della linea login_location: request.locationdi scrivere la posizione del IP l'accesso al database, come New York, cosa ottengo nel database è:
! --- ruby / oggetto: Geocoder :: Risultato :: Ipstack dati: ip: 127.0.0.1 COUNTRY_NAME: country_code Riservato: RD cache_hit:
Come faccio a salvare posizione sulla base della IP ad accedere nel mio database














