[code]
# products_controller.rb
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "foo" && password == "bar"
end
end
[/code]
# products_controller.rb
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "foo" && password == "bar"
end
end
[/code]
本文介绍了一个简单的Rails应用中用于用户身份验证的before_filter方法。通过HTTP Basic认证方式实现用户登录检查,确保只有输入了正确用户名'foo'及密码'bar'的用户才能访问受保护的资源。

被折叠的 条评论
为什么被折叠?



