Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Yik Yak类型用户模型和会话_Ruby On Rails_Postgresql_Ruby On Rails 4_Ip - Fatal编程技术网

Ruby on rails Yik Yak类型用户模型和会话

Ruby on rails Yik Yak类型用户模型和会话,ruby-on-rails,postgresql,ruby-on-rails-4,ip,Ruby On Rails,Postgresql,Ruby On Rails 4,Ip,我正在rails中构建一个匿名用户模型,每个用户通过IP地址进行区分。没有注册或登录本身。(假设它是一只牦牛克隆体)。我试图弄清楚如何构建用户模型,然后如何仅基于IP建立会话。这是怎么回事?如果我在搭建脚手架时将“ip”包含在表中,rails是否自动知道如何使用它 From http://www.yikyakapp.com/legal/ Yik Yak does maintain a log, however, of the following information for each mess

我正在rails中构建一个匿名用户模型,每个用户通过IP地址进行区分。没有注册或登录本身。(假设它是一只牦牛克隆体)。我试图弄清楚如何构建用户模型,然后如何仅基于IP建立会话。这是怎么回事?如果我在搭建脚手架时将“ip”包含在表中,rails是否自动知道如何使用它

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.

如果应用程序的每个实例只能有一个用户,请尝试以下操作。将其放入
users\u controller.rb
文件:

cattr_accessor :current_ip
在应用程序控制器中添加:

before_filter :set_current_ip

protected
def set_current_ip
    User.current_ip = request.env['REMOTE_ADDR']
end

你应该就你遇到的一个问题问一个具体的问题。现在,你的问题太广泛了,这不适合这个网站。另外,避免标签膨胀:这个问题与标签
user
ip
无关,可能与
postgresql
关系不大。所有这些信息都是相关的。谢谢,那么我会在用户模型中只包含一列“current_ip”吗?完全正确。然后你可以将其作为会话的基础。太好了,我如何保存每个用户?