2013-09-24 32 views
0

我使用谷歌oauth2時,我登錄使用谷歌,我選擇我的帳戶後,點擊輸入此錯誤顯示。AbstractController ActionNotFound失敗軌道3使用谷歌oauth2

AbstractController::ActionNotFound at /users/auth/google_oauth2/callback 
The action 'failure' could not be found for OmniauthCallbacksController 

我很難過!我做錯了什麼?

控制器omniauth

class OmniauthCallbacksController < ApplicationController 
    def google_oauth2 
     auth_details = request.env["omniauth.auth"] 
     if auth_details.info['email'].split("@")[1] == "company.net" 
      user = User.from_omniauth(request.env["omniauth.auth"]) 
      if user.persisted? 
       flash.notice = "Signed in Through Google!" 
       sign_in_and_redirect user 
      else 
       session["devise.user_attributes"] = user.attributes 
       flash.notice = "Please provide a password" 
       redirect_to new_user_registration_url 
      end 
     else 
      render :text => "Sorry this site is for company employees only" 
     end 
    end 
end 
在intializers

/devise.rb 我有config.omniauth要求

痕量

the error show this process actionpack-3.2.13/lib/abstract_controller/base.rb 

,這是線它突出顯示

unless action_name = method_for_action(action_name) 
    raise ActionNotFound, "The action" '#{action}' could not be found for #{self.class.name}" 
end 
+0

請出示痕跡。 –

+0

嗨,什麼是痕跡?謝謝 –

+0

Naomi,錯誤的回溯。屏幕上沒有失敗的方法,我不知道是什麼代碼調用它。 –

回答

1

我明白了。方法應該屬於Devise的控制器。您沒有從Devise繼承控制器,而是繼承了ApplicationController,因此無法找到此方法。

由於您正在實施基於設計的Omniauth,因此此控制器需要繼承Devise的設計。

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 

或者更好,添加命名空間的用戶,因爲控制器是在「應用程序/控制器/ users`

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 
+0

非常感謝!我如何才能做出需要遷移的變更?或者我可以手動做到這一點? –

+0

對於非命名空間版本,您只需重命名控制器即可。對於名稱空間,您需要更改名稱,並且如果您沒有這樣做,請定義路由:'devise_for:user,controllers:{omniauth_callbacks:'users/omniauth_callbacks'}'。不需要遷移,因爲這是針對控制器的。 –

+0

我使用命名空間版本 當我這樣做時,我得到未初始化的常量用戶,你知道爲什麼會發生? –