简体   繁体   English

“未初始化的常量用户(NameError)”w/Heroku 部署

[英]"uninitialized constant Users (NameError)" w/ Heroku deploy

I've built a basic Rails app with Mongoid, Devise and Omniauth for Facebook login.我用 Mongoid、Devise 和 Omniauth 构建了一个基本的 Rails 应用程序,用于 Facebook 登录。 I've got no problem running it locally, but when I try to push to Heroku, I'm getting this error:我在本地运行它没有问题,但是当我尝试推送到 Heroku 时,出现此错误:

"/app/app/controllers/Users/omniauth_callbacks_controller.rb:1:in `': uninitialized     constant Users (NameError)"

I've Googled the hell out of this with little luck.我用谷歌搜索了这个地狱,运气不佳。 I've committed the User model, I've ran "heroku run rake db:migrate", etc. No luck.我提交了用户 model,我运行了“heroku run rake db:migrate”等。没有运气。 Here's my stack.这是我的堆栈。

Ruby 1.9.2
Rails 3.2.1

Gemfile:宝石文件:

require 'rbconfig'
HOST_OS = RbConfig::CONFIG['host_os']
source 'https://rubygems.org'
gem 'rails', '3.2.1'
group :assets do
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'

gem "bson_ext", ">= 1.6.1"
gem "mongoid"
gem "devise"
gem "zurb-foundation"
gem "omniauth"
gem 'omniauth-facebook'
gem 'gravatar_image_tag'

Gemfile.lock:宝石文件锁:

GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.1)
  actionpack (= 3.2.1)
  mail (~> 2.4.0)
actionpack (3.2.1)
  activemodel (= 3.2.1)
  activesupport (= 3.2.1)
  builder (~> 3.0.0)
  erubis (~> 2.7.0)
  journey (~> 1.0.1)
  rack (~> 1.4.0)
  rack-cache (~> 1.1)
  rack-test (~> 0.6.1)
  sprockets (~> 2.1.2)
activemodel (3.2.1)
  activesupport (= 3.2.1)
  builder (~> 3.0.0)
activerecord (3.2.1)
  activemodel (= 3.2.1)
  activesupport (= 3.2.1)
  arel (~> 3.0.0)
  tzinfo (~> 0.3.29)
activeresource (3.2.1)
  activemodel (= 3.2.1)
  activesupport (= 3.2.1)
activesupport (3.2.1)
  i18n (~> 0.6)
  multi_json (~> 1.0)
addressable (2.2.7)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bson (1.6.1)
bson_ext (1.6.1)
  bson (~> 1.6.1)
builder (3.0.0)
coffee-rails (3.2.2)
  coffee-script (>= 2.2.0)
  railties (~> 3.2.0)
coffee-script (2.2.0)
  coffee-script-source
  execjs
coffee-script-source (1.2.0)
devise (2.0.4)
  bcrypt-ruby (~> 3.0)
  orm_adapter (~> 0.0.3)
  railties (~> 3.1)
  warden (~> 1.1.1)
erubis (2.7.0)
execjs (1.3.0)
  multi_json (~> 1.0)
faraday (0.7.6)
  addressable (~> 2.2)
  multipart-post (~> 1.1)
  rack (~> 1.1)
gravatar_image_tag (1.0.0)
hashie (1.2.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.2)
  railties (>= 3.2.0, < 5.0)
  thor (~> 0.14)
json (1.6.6)
mail (2.4.4)
  i18n (>= 0.4.0)
  mime-types (~> 1.16)
  treetop (~> 1.4.8)
mime-types (1.18)
mongo (1.6.1)
  bson (~> 1.6.1)
mongoid (2.4.7)
  activemodel (~> 3.1)
  mongo (~> 1.3)
  tzinfo (~> 0.3.22)
multi_json (1.2.0)
multipart-post (1.1.5)
oauth2 (0.5.2)
  faraday (~> 0.7)
  multi_json (~> 1.0)
omniauth (1.0.3)
  hashie (~> 1.2)
  rack
omniauth-facebook (1.2.0)
  omniauth-oauth2 (~> 1.0.0)
omniauth-oauth2 (1.0.0)
  oauth2 (~> 0.5.0)
  omniauth (~> 1.0)
orm_adapter (0.0.7)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
  rack (>= 0.4)
rack-ssl (1.3.2)
  rack
rack-test (0.6.1)
  rack (>= 1.0)
rails (3.2.1)
  actionmailer (= 3.2.1)
  actionpack (= 3.2.1)
  activerecord (= 3.2.1)
  activeresource (= 3.2.1)
  activesupport (= 3.2.1)
  bundler (~> 1.0)
  railties (= 3.2.1)
railties (3.2.1)
  actionpack (= 3.2.1)
  activesupport (= 3.2.1)
  rack-ssl (~> 1.3.2)
  rake (>= 0.8.7)
  rdoc (~> 3.4)
  thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
  json (~> 1.4)
sass (3.1.15)
sass-rails (3.2.5)
  railties (~> 3.2.0)
  sass (>= 3.1.10)
  tilt (~> 1.3)
sprockets (2.1.2)
  hike (~> 1.2)
  rack (~> 1.0)
  tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
  polyglot
  polyglot (>= 0.3.1)
tzinfo (0.3.32)
uglifier (1.2.4)
  execjs (>= 0.3.0)
  multi_json (>= 1.0.2)
warden (1.1.1)
  rack (>= 1.0)
zurb-foundation (2.2.0.2)
  jquery-rails (>= 1.0)
  rails (~> 3.1)

PLATFORMS
ruby

DEPENDENCIES
 bson_ext (>= 1.6.1)
 coffee-rails (~> 3.2.1)
 devise
 gravatar_image_tag
 jquery-rails
 mongoid
 omniauth
 omniauth-facebook
 rails (= 3.2.1)
 sass-rails (~> 3.2.3)
 uglifier (>= 1.0.3)
 zurb-foundation

Controller: Controller:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
  # You need to implement the method below in your model
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

if @user.persisted?
  flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
  sign_in_and_redirect @user, :event => :authentication
else
  session["devise.facebook_data"] = request.env["omniauth.auth"]
  redirect_to new_user_registration_url
end
end
end

Any thoughts?有什么想法吗?

I had this issue;我遇到了这个问题; I know it's a late answer but I wanted to add this for whoever needed it.我知道这是一个迟到的答案,但我想为需要它的人添加它。

Make sure that your OmniauthCallbacksController IS IN A users FOLDER.确保您的 OmniauthCallbacksController 在users文件夹中。 "app/controllers/users/omniauth_callbacks_controller.rb"

Just thought I'd add that I had this issue and that the above solutions didn't work for me.只是想补充一点,我遇到了这个问题,并且上述解决方案对我不起作用。 It turns out the cause in my case was that Devise had capitalized the Users subfolder's name (/app/app/controllers/Users).事实证明,在我的案例中,原因是 Devise 将用户子文件夹的名称 (/app/app/controllers/Users) 大写。 Deleting the folder from git and then readding it with the proper lowercase name of "users" (/app/app/controllers/users) solved my issue.从 git 中删除文件夹,然后使用正确的小写名称“用户”(/app/app/controllers/users) 读取它解决了我的问题。

Unlikely, but if you used "rails generate scaffold", or "rails generate controller" to create the controller, you need to "git add -A" to add all the newly created files to your repository.不太可能,但如果您使用“rails generate scaffold”或“rails generate controller”来创建 controller,则需要“git add -A”将所有新创建的文件添加到您的存储库。 (1) git add -A (2) git commit -m "new files added" (3) git push [assuming you're also using a remote repo] (4) git push heroku master (5) heroku run rake db:migrate (1) git add -A (2) git commit -m "new files added" (3) git push [假设你也在使用远程仓库] (4) git push heroku master (5) 88546389507迁移

This would be a "Rookie Mistake", but would explain the error above.这将是一个“菜鸟错误”,但可以解释上面的错误。 Don't ask how I know!别问我怎么知道!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部署到heroku时控制器中未初始化的常量错误 - Uninitialized constant error in controller when deploy to heroku Rails 3:Heroku中未初始化的常量IRB :: ReadlineInputMethod :: Readline(NameError) - Rails 3: uninitialized constant IRB::ReadlineInputMethod::Readline (NameError) in Heroku Heroku Rails 3 App Deployment未初始化的常量Mail :: TestMailer(NameError) - Heroku Rails 3 App Deployment uninitialized constant Mail::TestMailer (NameError) Heroku NameError(未初始化的常量ApplicationController :: ADMIN_ID) - Heroku NameError (uninitialized constant ApplicationController::ADMIN_ID) NameError未初始化的常量 - NameError uninitialized constant 未初始化的常量OpenSSL(NameError) - uninitialized constant OpenSSL (NameError) heroku无法正常工作/heroku/commands/pgbackups.rb:9:in <class:Pgbackups> &#39;:未初始化的常量Heroku :: Command :: Pgbackups :: Help(NameError) - heroku not working /heroku/commands/pgbackups.rb:9:in `<class:Pgbackups>': uninitialized constant Heroku::Command::Pgbackups::Help (NameError) NameError:未初始化的常量String :: Stemmer - NameError: uninitialized constant String::Stemmer 带有rails 3的未初始化的常量Bundler(NameError) - uninitialized constant Bundler (NameError) with rails 3 NameError(未初始化的常量ActionDispatch :: ExceptionWrapper): - NameError (uninitialized constant ActionDispatch::ExceptionWrapper):
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM