2012-04-04 55 views
1

我试图基于某个IP进行身份验证,如果IP不正确,则访问应该是不允许的。使用application_controller只从某个ip认证可能吗?

林:

before_filter :authenticate 
    def authenticate 
    authenticate_or_request_with_http_basic do |username, password| 
     username == "admin" && password == "talkmate" 
    end 
    end 

什么是增加检查IP,如果IP是不是一定值时禁止访问正确的方法是什么?

回答

3

检查request.remote_ip。如果不正确,则显示错误消息或重定向到错误页面(或其他)。

+0

thx完全做到了! – Rubytastic 2012-04-04 13:09:40

+0

接受它然后:) – 2012-04-04 13:14:47

+0

Coudent接受我不得不等待几分钟,完成;)thx再次 – Rubytastic 2012-04-04 13:17:48