【发布时间】:2011-11-04 19:40:33
【问题描述】:
我想检查设备 ip 地址访问我的站点 (root to=>home#index) 的次数,如果该地址多次访问我的站点,则执行一段代码(任何内容)。我如何使用 rails 完成此操作?换句话说,我如何访问和设置一个变量来存储index action 中的用户 ip_address 登录数?根页面是 home#index。为了澄清更多用户不必是注册用户,我只想通过计算机跟踪ip 地址。我需要帮助以注释掉索引操作中的单词。有设计current_sign_in_ip 但我不确定这是否是为了解决这个问题,因为我对设计和轨道都很陌生。非常感谢!
控制器
class HomeController < ApplicationController
def index
#access user ip address
#set a variable to increment number of times the address come to a site
# if no_of_ip_login is_greater_than_1 #In other words if it is a returning user
redirect_to :controller=>"home" ,:action=>"show"
end
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 devise ruby-on-rails-3.1 request