我正在制作一个简单的博客来学习 Rails。
一切都快完成了,我正在尝试应用 HTTP 身份验证,如此处所述 --> http://berk.es/2011/03/29/simplest-authentication-in-rails-basic-authentication-with-a -logged_in-helper/
我的身份验证代码在 ApplicationController 中如下所示
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == ADMIN_ID && password == ADMIN_PASSWORD
end
end
end
但是,我不想在我的文件中传递变量,而是想通过 heroku 传递它。所以我跑了-->
heroku config:add ADMIN_ID=myusername
heroku config:add ADMIN_PASSWORD=mypassword
当我尝试登录时,虽然我收到“出现问题”消息。这是heroku日志所说的:
GET fast-chamber-1998.herokuapp.com/admin dyno=web.1 queue=0 wait=0ms service=10ms status=500 bytes=643
2012-11-11T07:18:47+00:00 app[web.1]:
2012-11-11T07:18:47+00:00 app[web.1]:
2012-11-11T07:18:47+00:00 app[web.1]: Started GET "/admin" for 60.245.65.132 at 2012-11-11 07:18:47 +0000
2012-11-11T07:18:47+00:00 app[web.1]: Processing by PostsController#admin as HTML
2012-11-11T07:18:47+00:00 app[web.1]: Completed 500 Internal Server Error in 1ms
2012-11-11T07:18:47+00:00 app[web.1]:
2012-11-11T07:18:47+00:00 app[web.1]: NameError (uninitialized constant ApplicationController::ADMIN_ID):
2012-11-11T07:18:47+00:00 app[web.1]: app/controllers/application_controller.rb:7:in `block in authenticate'
2012-11-11T07:18:47+00:00 app[web.1]: app/controllers/application_controller.rb:6:in `authenticate'
2012-11-11T07:18:47+00:00 app[web.1]:
2012-11-11T07:18:47+00:00 app[web.1]:
从外观上看,我认为我传递的环境变量似乎没有被检测到。你建议我怎么做?