ruby-on-rails – Rails 3 http_basic_authenticate_with只在生产环境中?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails 3 http_basic_authenticate_with只在生产环境中?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法才能使用
  1. http_basic_authenticate_with :name => 'user',:password => 'secret'

当服务器在生产模式下运行时?

解决方法

是的,尝试:
  1. class ApplicationController < ActionController::Base
  2. before_filter :authenticate
  3.  
  4. def authenticate
  5. if Rails.env.production?
  6. authenticate_or_request_with_http_basic do |username,password|
  7. username == "user" && password == "%$§$§"
  8. end
  9. end
  10. end
  11. end

猜你在找的Ruby相关文章