我正在制作一个简单的博客来学习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传递它。所以我跑了 - &gt;
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]:
从它的外观来看,我认为我传递的环境变量似乎没有被检测到。你有什么建议我这样做?
答案 0 :(得分:0)
您应该以{{1}}和ENV['ADMIN_ID']