I’m making a simple blog to learn rails.
Everything is almost finished, and I’m trying to apply HTTP authentication, as outlined here –> http://berk.es/2011/03/29/simplest-authentication-in-rails-basic-authentication-with-a-logged_in-helper/
My authentication code looks like this, in the 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
instead of passing the variable in my files, however, I want to pass it through heroku. So I ran –>
heroku config:add ADMIN_ID=myusername
heroku config:add ADMIN_PASSWORD=mypassword
When I tried logging in though I get a “Something went wrong” message. Here’s what heroku logs say :
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]:
From the looks of it, I think the environment variables I passed don’t seem to be detected. What do you suggest I do?
You should access them as
ENV['ADMIN_ID']andENV['ADMIN_PASSWORD']