“未初始化的常量用户(NameError)” w / Heroku部署 [英] "uninitialized constant Users (NameError)" w/ Heroku deploy

查看:118
本文介绍了“未初始化的常量用户(NameError)” w / Heroku部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个基本的Rails应用程序与Mongoid,Devise和Omniauth进行Facebook登录。我在本地运行它没有问题,但是当我尝试推送到Heroku时,我收到这个错误:

  /app/app/controllers/Users/omniauth_callbacks_controller.rb:1:in':未初始化的常量用户(NameError)

我已经把这个死了,没有什么好运气。我已经提交了用户模型,我已经运行了heroku run rake db:migrate等等。没有运气。这是我的堆栈。

  Ruby 1.9.2 
Rails 3.2.1

Gemfile:

  require'rbconfig'
HOST_OS = RbConfig :: CONFIG ['host_os']
源'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'

gembson_ext, > = 1.6.1
gemmongoid
gemdevise
gemzurb-foundation
gemomniauth
gem'omniauth-facebook '
gem'gravatar_image_tag'

Gemfile.lock:

  GEM 
remote:https://rubygems.org/
规格:
actionmailer(3.2.1)
actionpack(= 3.2.1)
mail(〜> 2.4.0)
actionpack(3.2.1)
activemodel(= 3.2.1)
activesupport(= 3.2 $)
生成器(〜> 3.0.0)
erubis(〜> 2.7.0)
旅程(〜> 1.0.1)
机架(〜> ; 1.4.0)
机架缓存(〜> 1.1)
机架测试(〜> 0.6.1)
链轮(〜> 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)
可寻址(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)
咖啡脚本(> = 2.2.0)
railties(〜> 3.2.0)
咖啡脚本(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)
法拉第(0.7.6)
可寻址(〜> 2.2)
multipart-post(〜> 1.1)
机架> 1.1)
gravatar_image_tag(1.0.0)
哈希(1.2.0)
远足(1.2.1)
i18n(0.6.0)
旅程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)
树顶(〜> 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)
法拉第(〜> 0.7)
multi_json(〜> 1.0)
omniauth(1.0.3)
(〜> 1.2)
机架
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)
机架缓存(1.2)
机架(> = 0.4)
rack-ssl(1.3.2)
机架
机架测试(0.6.1)
机架(> = 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)
activ esupport(= 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)
倾斜(〜> 1.3)
链轮(2.1.2)
远足(〜> 1.2)
机架(〜> 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)
机架(> = 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

控制器:

  class Users :: OmniauthCallbacksController< Devise :: OmniauthCallbacksController 
def facebook
#你需要在你的模型中实现下面的方法
@user = User.find_for_facebook_oauth(request.env [omniauth.auth],current_user)

如果@ user.persisted?
flash [:notice] = I18n.tdevise.omniauth_callbacks.success,:kind => Facebook
sign_in_and_redirect @user,:event => :验证
else
会话[devise.facebook_data] = request.env [omniauth.auth]
redirect_to new_user_registration_url
end
end
结束

任何想法?

解决方案

我有这个问题;我知道这是一个迟到的答案,但我想为任何需要的人添加这个。



确保你的OmniauthCallbacksController在一个用户 FOLDER。 app / controllers / users / omniauth_callbacks_controller.rb


I've built a basic Rails app with Mongoid, Devise and Omniauth for Facebook login. I've got no problem running it locally, but when I try to push to Heroku, I'm getting this error:

"/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. 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:

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. "app/controllers/users/omniauth_callbacks_controller.rb"

这篇关于“未初始化的常量用户(NameError)” w / Heroku部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆