В ваших контроллерах вы можете получить доступ к текущему IP через request.remote_ip
.
Таким образом, вы можете переписать authenticate_user!
метод devise или просто написать свой собственный before_action
.Для этого требуется столбец current_ip
в модели User
.
class ApplicationController < ActionController::Base
before_action :hit_user
def current_ip
# request is the object that carries all the information from the
# request to the controller
request.remote_ip
end
private
def hit_user
current_user.hit!(current_ip)
end
end
class User < ApplicationRecord
def hit!(current_ip)
# use update_attribute since this happens on every request and you
# dont want to trigger User validations all the time
self.update_attribute(current_ip: current_ip)
end
end
Таким образом, у вас есть current_ip и последний, который использовался для запроса.