我在rails中构建匿名用户模型,每个用户都按IP地址区分。没有注册或登录本身。 (让我们说它是Yik Yak克隆)。我试图弄清楚如何构建用户模型,然后如何建立基于IP的会话。这是如何运作的? rails会自动知道如何使用" ip"如果我在脚手架中把它包括在桌子里?
From http://www.yikyakapp.com/legal/
Yik Yak does maintain a log, however, of the following information for each message posted:
- The IP address from which the message was posted;
- The GPS coordinates of the location from which the message was posted;
- The time and date when the message was posted.
答案 0 :(得分:0)
如果您的应用的每个实例只能拥有一个用户,请尝试以下操作。将其放在users_controller.rb
文件中:
cattr_accessor :current_ip
在您的应用程序控制器中添加:
before_filter :set_current_ip
protected
def set_current_ip
User.current_ip = request.env['REMOTE_ADDR']
end