使用密码保护管理员控制器

时间:2014-03-11 12:26:46

标签: ruby-on-rails

我想用密码保护我的管理员控制器。我补充说:

  before_filter :authenticate

  protected
  def authenticate
    authenticate_or_request_with_http_basic do |username, password|
      username == "user" && password == "pass!"
    end
  end

进入admins_controller.rb,但当我访问/admins/admins/sign_inadmins/sign_up等任何管理员路线时,系统不会显示任何对话框供用户输入凭据。

之前我用它来保护整个页面,方法是将它放在application_controller.rb;与我现在使用的方式完全相同,之前它运行良好。

有什么可能是错的? (p.s.我使用设计)

1 个答案:

答案 0 :(得分:0)

试试这个:

protected
def authenticate
  authenticate_or_request_with_http_basic_with name: "user", password: "pass!"
end