我正在rails中构建一个匿名用户模型,每个用户通过IP地址来区分。没有注册或登录本身。(假设它是一个Yak 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.发布于 2015-07-07 12:13:00
如果您的应用程序的每个实例只能有一个用户,请尝试以下方法。将以下内容放入您的users_controller.rb文件中:
cattr_accessor :current_ip在您的应用程序控制器中添加:
before_filter :set_current_ip
protected
def set_current_ip
User.current_ip = request.env['REMOTE_ADDR']
endhttps://stackoverflow.com/questions/31259390
复制相似问题