![](/img/trans.png)
[英]uninitialized constant ApplicationController (NameError)
[英]NameError (uninitialized constant ApplicationController::ADMIN_USERNAME):
我有一個帶有密碼保護的管理區域的簡單網站。 它在開發中效果很好。 當我上傳到Heroku時,出現以下錯誤:
NameError (uninitialized constant ApplicationController::ADMIN_USERNAME):
我的應用程序控制器:
class ApplicationController < ActionController::Base
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == ENV[ADMIN_USERNAME] && password == ENV[ADMIN_PASSWORD]
end
end
end
管理員/ index_controller:
class Admin::IndexController < ApplicationController
before_filter :authenticate
def index
end
end
我已經將heroku env varibale設置為:
heroku config:add ADMIN_USERNAME:'myusername'
我找不到下一步該做什么。
您需要使用ENV['ADMIN_USERNAME']
,否則應用程序會認為這是一個常量名稱。 奇怪的是,這在開發中起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.