2013-10-25 7 views
1

ну, я пытаюсь закодировать систему, которая использует facebook login. Когда я нажимаю ссылку на facebook, она переходит на страницу facebook для аутентификации, а на обратном вызове показывает мне эту ошибку: невозможно автозагрузка констант. Пользователи :: OmniauthCallbacksController, ожидаемый путь /app/controllers/users/omniauth_callbacks_controller.rb, чтобы определить его. Я использую изобрести камень, OmniAuth камень, рубин 2 и рельсы 4.LoadError in Users :: OmniauthCallbacksController # facebook - Rails 4

Мой user_controller.rb

class User::OmniauthCallbacksController < Devise::OmniauthCallbacksController 
    def facebook 
    @user = User.find_for_facebook_oauth(request.env['omniauth.auth'], current_user) 
    if @user.persisted? 
     sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated 
     set_flash_message(:notice, :success, :kind => 'Facebook') if is_navigational_format? 
    else 
     session['devise.facebook_data'] = request.env['omniauth.auth'] 
     redirect_to new_user_registration_url 
    end 
    end 
end 

Мой user.rb

class User < ActiveRecord::Base 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable, :omniauthable 

    def self.find_for_facebook_oauth(auth, signed_in_resource = nil) 
    user = User.where(:provider => auth.provider, :uid => auth.uid).first 
    if user 
     return user 
    else 
     registered_user = User.where(:email => auth.info.email).first 
     if registered_user 
     return registered_user 
     else 
     user = User.create(name:auth.extra.raw_info.name, 
          provider:auth.provider, 
          uid:auth.uid, 
          email:auth.info.email, 
          password:Devise.friendly_token[0,20], 
     ) 
     end 
    end 
    end 
end 

На маршрутах. rb У меня есть эта строка:

devise_for :users, :controllers => { :omniauth_callbacks => 'users/omniauth_callbacks' } 

Полный Трассировка это:

activesupport (4.0.0) lib/active_support/dependencies.rb:463:in `load_missing_constant' 
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing' 
activesupport (4.0.0) lib/active_support/inflector/methods.rb:228:in `const_get' 
activesupport (4.0.0) lib/active_support/inflector/methods.rb:228:in `block in constantize' 
activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `each' 
activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `inject' 
activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `constantize' 
activesupport (4.0.0) lib/active_support/dependencies.rb:534:in `get' 
activesupport (4.0.0) lib/active_support/dependencies.rb:565:in `constantize' 
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:76:in `controller_reference' 
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:66:in `controller' 
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:44:in `call' 
actionpack (4.0.0) lib/action_dispatch/routing/mapper.rb:44:in `call' 
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call' 
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each' 
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call' 
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call' 
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!' 
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call' 
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!' 
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call' 
omniauth (1.1.4) lib/omniauth/strategy.rb:401:in `call_app!' 
omniauth (1.1.4) lib/omniauth/strategy.rb:363:in `callback_phase' 
omniauth-oauth2 (1.1.1) lib/omniauth/strategies/oauth2.rb:77:in `callback_phase' 
omniauth (1.1.4) lib/omniauth/strategy.rb:226:in `callback_call' 
omniauth (1.1.4) lib/omniauth/strategy.rb:182:in `call!' 
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call' 
warden (1.2.3) lib/warden/manager.rb:35:in `block in call' 
warden (1.2.3) lib/warden/manager.rb:34:in `catch' 
warden (1.2.3) lib/warden/manager.rb:34:in `call' 
rack (1.5.2) lib/rack/etag.rb:23:in `call' 
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call' 
rack (1.5.2) lib/rack/head.rb:11:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call' 
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context' 
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call' 
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call' 
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call' 
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__878755641__call__callbacks' 
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks' 
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app' 
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call' 
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged' 
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged' 
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged' 
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call' 
rack (1.5.2) lib/rack/runtime.rb:17:in `call' 
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call' 
rack (1.5.2) lib/rack/lock.rb:17:in `call' 
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call' 
railties (4.0.0) lib/rails/engine.rb:511:in `call' 
railties (4.0.0) lib/rails/application.rb:97:in `call' 
rack (1.5.2) lib/rack/lock.rb:17:in `call' 
rack (1.5.2) lib/rack/content_length.rb:14:in `call' 
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service' 
C:/Development/Ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' 
C:/Development/Ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' 
C:/Development/Ruby200/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread' 

Так что это моя проблема, я надеюсь, что кто-то может мне помочь.

EDIT:, а не то, что я подразумевал, мой контроллер обратных вызовов называется omniauth_callbacks_controller.rb. 1. Как sevenseacat предложил я изменил ссылку от пользователей к пользователя на моем файле маршрута, но проблема все еще произошло. 2. Как * uno_ordinary * предложил я добавил : omniauth_providers =>: facebook на моей модели, но после этого я получил новую ошибку при запуске сервера:

=> Booting WEBrick 
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000 
=> Run `rails server -h` for more startup options 
=> Ctrl-C to shutdown server 
Exiting 
C:3:in `rescue in execute_if_updated': Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x4375db8 @paths=["C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config/routes.rb"], @route_sets=[#<ActionDispatch::Routing::RouteSet:0x449da98>]> (RuntimeError) 
     from C:131071:in `execute_if_updated' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers' 
     from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each' 
     from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component' 
     from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from' 
     from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component' 
     from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:180:in `each' 
     from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component' 
     from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing' 
     from C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config/environment.rb:5:in `<top (required)>' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require' 
     from C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config.ru:3:in `block in <main>' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize' 
     from C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config.ru:in `new' 
     from C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config.ru:in `<main>' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:48:in `app' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:75:in `start' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap' 
     from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>' 
     from bin/rails:4:in `require' 
     from bin/rails:4:in `<main>' 

ответ

0

Try добавить к модели User следующие: :omniauthable, :omniauth_providers => [:facebook]

0

Если ваш контроллер обратных вызовов находится в файле с именем user_controller.rb (как следует из вашего сообщения), это неверно.

Чтобы следовать соглашениям об именах Rails, оно должно быть в app/controllers/users/omniauth_callbacks_controller.rb (как сообщает об ошибке).

У вас также возникла проблема с namespacing - ваш маршрут для контроллера обратных вызовов относится к users (множественное число), а пространство имен вашего контроллера - User (единственное число).

Смежные вопросы