Wenn ich in der Anwendung anmelden, wird der Code unten genannt. So in dem SessionsController, wird SignupHistory Tabelle mit dem bevölkerten .createVerfahren.
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
Datenbankattribute
Doch statt der Zeile login_location: request.locationder Position des IP zu schreiben , in in die Datenbank der Unterzeichnung wie das New York, was ich in der Datenbank erhalten ist:
! --- ruby / Objekt: Geocoder :: Ergebnis :: IP-Stack Daten: ip: 127.0.0.1 country_name: Reserviert country_code: RD cache_hit:
Wie speichere ich Standort auf der Grundlage der IP-in in meine Datenbank Unterzeichnung














