2012-04-10 18 views
1

前方このコントローラに私と私はこの初期化されていない定数を解決するにはUsersController :: LinkedIn? LinkedInのからの検証が成功した後

初期化されていない定数がUserControllerを取得する::認証が成功したら、コントロールがどこに行くのLinkedIn

これがあります。

class UsersController < ApplicationController 
    def index 
    # get your api keys at https://www.linkedin.com/secure/developer 
    client = LinkedIn::Client.new("ddddd", "eeeee") 
    request_token = client.request_token(:oauth_callback =>"http://localhost:3000/users/callback") 
    session[:rtoken] = request_token.token 
    session[:rsecret] = request_token.secret 
    redirect_to client.request_token.authorize_url 
    end 

    def callback 
    client = LinkedIn::Client.new("dddd", "eeeeee") 
    if session[:atoken].nil? 
     pin = params[:oauth_verifier] 
     atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin) 
     session[:atoken] = atoken 
     session[:asecret] = asecret 
    else 
     client.authorize_from_access(session[:atoken], session[:asecret]) 
    end 
    @profile = client.profile 
    @connections = client.connections 
    end 
end 

完全なトレース:

pp/controllers/users_controller.rb:4:in `index' 
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
actionpack (3.2.1) lib/abstract_controller/base.rb:167:in `process_action' 
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action' 
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:18:in `process_action' 
activesupport (3.2.1) lib/active_support/callbacks.rb:414:in `_run__434435962__process_action__199225275__callbacks' 
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `send' 
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback' 
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' 
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `send' 
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks' 
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action' 
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action' 
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action' 
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument' 
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument' 
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action' 
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action' 
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process' 
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process' 
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch' 
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' 
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `action' 
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call' 
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch' 
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call' 
journey (1.0.3) lib/journey/router.rb:68:in `call' 
journey (1.0.3) lib/journey/router.rb:56:in `each' 
journey (1.0.3) lib/journey/router.rb:56:in `call' 
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call' 
omniauth (1.0.3) lib/omniauth/strategy.rb:168:in `call!' 
omniauth (1.0.3) lib/omniauth/strategy.rb:148:in `call' 
omniauth (1.0.3) lib/omniauth/builder.rb:42:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' 
rack (1.4.1) lib/rack/etag.rb:23:in `call' 
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call' 
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context' 
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call' 
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call' 
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `call' 
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__397314981__call__4__callbacks' 
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `send' 
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback' 
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' 
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `send' 
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks' 
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app' 
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call' 
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call' 
rack (1.4.1) lib/rack/runtime.rb:17:in `call' 
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
rack (1.4.1) lib/rack/lock.rb:15:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call' 
railties (3.2.1) lib/rails/engine.rb:479:in `call' 
railties (3.2.1) lib/rails/application.rb:220:in `call' 
rack (1.4.1) lib/rack/content_length.rb:14:in `call' 
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call' 
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:162:in `start' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:95:in `start' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:92:in `each' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:92:in `start' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:23:in `start' 
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/webrick/server.rb:82:in `start' 
rack (1.4.1) lib/rack/handler/webrick.rb:13:in `run' 
rack (1.4.1) lib/rack/server.rb:265:in `start' 
railties (3.2.1) lib/rails/commands/server.rb:70:in `start' 
railties (3.2.1) lib/rails/commands.rb:55 
railties (3.2.1) lib/rails/commands.rb:50:in `tap' 
railties (3.2.1) lib/rails/commands.rb:50 
script/rails:6:in `require' 
script/rails:6 

SessionController:

class SessionsController < ApplicationController 
     def create 
     auth = request.env["omniauth.auth"] 
     puts "printing" 
     puts auth 
     session[:rtoken] = params[:token] 
     session[:rsecret] = params[:secret] 
     client = LinkedIn::Client.new("cus7tde3g4pe", "jKf6ZYgf8JhMoIJ4") 
     if session[:atoken].nil? 
      pin = params[:oauth_verifier] 
      atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin) 
      session[:atoken] = atoken 
      session[:asecret] = asecret 
     else 
      client.authorize_from_access(session[:atoken], session[:asecret]) 
     end 
     @profile = client.profile 
     @connections = client.connections 
     end 
     #user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth) 
     session[:user_id] = profile.name 
     redirect_to root_url, :notice => "Signed in!" 
     #end 

     def destroy 
     session[:user_id] = nil 
     redirect_to root_url, :notice => "Signed out!" 
     end 
    end 

Full Trace : 

C:/linkedin/lovelinkedin/app/controllers/sessions_controller.rb:21: undefined local variable or method `session' for Ses 
sionsController:Class (NameError) 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
51:in `require' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
51:in `require' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
36:in `load_dependency' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
51:in `require' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:3 
59:in `require_or_load' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:3 
13:in `depend_on' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
25:in `require_dependency' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:439:in `eager_load!' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:438:in `each' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:438:in `eager_load!' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:436:in `each' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:436:in `eager_load!' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/application/finisher.rb:53 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instanc 
e_exec' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `run_ini 
tializers' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_ini 
tializers' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/application.rb:136:in `initiali 
ze!' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in ` 
send' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in ` 
method_missing' 
     from C:/linkedin/lovelinkedin/config/environment.rb:5 
     from ./test/test_helper.rb:2:in `require' 
     from ./test/test_helper.rb:2 
     from C:/linkedin/lovelinkedin/test/unit/helpers/linkedin_helper_test.rb:1:in `require' 
     from C:/linkedin/lovelinkedin/test/unit/helpers/linkedin_helper_test.rb:1 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:15:in `require 
' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:15 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4 
C:/linkedin/lovelinkedin/app/controllers/sessions_controller.rb:21: undefined local variable or method `session' for Ses 
sionsController:Class (NameError) 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
51:in `require' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
51:in `require' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
36:in `load_dependency' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
51:in `require' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:3 
59:in `require_or_load' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:3 
13:in `depend_on' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:2 
25:in `require_dependency' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:439:in `eager_load!' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:438:in `each' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:438:in `eager_load!' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:436:in `each' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:436:in `eager_load!' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/application/finisher.rb:53 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instanc 
e_exec' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `run_ini 
tializers' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_ini 
tializers' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/application.rb:136:in `initiali 
ze!' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in ` 
send' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in ` 
method_missing' 
     from C:/linkedin/lovelinkedin/config/environment.rb:5 
     from ./test/test_helper.rb:2:in `require' 
     from ./test/test_helper.rb:2 
     from C:/linkedin/lovelinkedin/test/functional/linkedin_controller_test.rb:1:in `require' 
     from C:/linkedin/lovelinkedin/test/functional/linkedin_controller_test.rb:1 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:15:in `require 
' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:15 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select' 
     from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4 

私はRORに新しい男だと私はこの問題を解決するのに役立ちます。

+0

完全なエラーメッセージを投稿してください。 –

+0

@SiweiShen今投稿をご覧ください。お返事ありがとうございます – SAR

+1

あなたのGemfileのRailsアプリケーションフォルダの下に 'gem 'linkedin''がありますか? –

答えて

2

ごsessions_controller質問の更新された答え:

あなたは[アクション]内の「セッション」を使用する必要があり、例えばあなたの現在のコード:

class SessionsController < ApplicationController 
    def create 
    # ... some code for create action 
    end 

# NOTICE: these 4 lines of code should be placed in an "action" 
#user = User.find_by_provider_and_uid(auth["pr 
session[:user_id] = profile.name 
redirect_to root_url, :notice => "Signed in!" 
#end 

    def destroy 
    # ... some code for destroy action 
    end 
end 

Railsは、 "セッション" をrecorgnizeことができるようにあなたは、行動にコードの4行を移動する必要があります。

class SessionsController < ApplicationController 
    def create 
    # ... some code for create action 
    session[:user_id] = profile.name 
    redirect_to root_url, :notice => "Signed in!" 
    end 

===========

あなたはRails3を使用している場合、あなたはGemfileに、すべてのRubyGemsを追加する必要があり、例えば:

前の質問のために==

ANSWER

gem "rake", "0.8.7" 
gem 'rails', '3.0.5' 
gem 'linkedin' 

ここでは、gem 'linkedin'を追加することで、ルビーコードはすべてのものを含めることができるようになりました。

廃止されたRails 2.x WAY:これをしないと、コントローラーにrequireステートメントを追加する必要があります。

# don't do this if you are using Gemfile 
require 'linkedin' 
class UsersController < ApplicationController 
    def index 
    # ... 
end 
+0

私はレール3.2.1を使用しています – SAR

関連する問題