2012-12-05 32 views
7

herokuでホストされているアプリでdevise、omniauth(facebook-omniauthを含む)を使ってfacebook認証を設定しようとしています。 Call to facebook APIは機能しますが、コールバック後に確認手順をスキップすることはできません。未定義のメソッドskip_confirmation! - devise、omniauth

私はomniauthにgithubのチュートリアルに続く:https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

をしても読み、これを実装してみました: Devise skip_confirmation! not working

をしかし、私は私のHerokuのログに次のエラーを取得しておいてください。

NoMethodError (undefined method `skip_confirmation!') 

私のdevise.rbの外観は次のとおりです。

config.omniauth :facebook, "API_KEY", "API_SECRET"  

{:strategy_class => OmniAuth::Strategies::Facebook, 
:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}} 
あなたの助けのための

def self.find_for_facebook_oauth(auth, signed_in_resource=nil) 
user = User.where(:provider => auth.provider, :uid => auth.uid).first 
unless user 
     user = User.new(name:auth.extra.raw_info.name, 
        provider:auth.provider, 
        uid:auth.uid, 
        email:auth.info.email, 
        password:Devise.friendly_token[0,20], 
        ) 
     user.skip_confirmation! 
     user.save 
    end 
    user 
end 

ありがとう:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 
    def facebook 
    # You need to implement the method below in your model (e.g. app/models/user.rb) 
    @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モデルです:

は、ここに私のomniauth_callbacks_controller.rbです!

+0

あなたは確認できるモジュールをユーザーに持っていますか? Userクラス rorra

+0

私はこれを持っていますこれを逃した! 私は__railsグラムの移行add_confirmable_to_devise__と熊手デシベルを走った、__confirmable__ user.rbを追加しました: を移行する今、私はNoMethodError取得OmniauthCallbacksControllerに(未定義のメソッド 'is_navigational_formatを '?)。私はなぜそれを見つける必要があります! –

答えて

16

私は(100%安全ではありません)右だのであれば、あなたは、あなたのモデルが確認できるモジュールを持っていることを宣言する確認できるモジュールを追加する必要があります。

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :confirmable 

をそして、あなたはのフィールドを持っていることを確認してくださいあなたのusersテーブルの確認可能なモジュールには、confirm_tokenとconfirmed_atというフィールドがあります。

これらのフィールドがない場合は、これをチェックするにはanswerをチェックしてください。

+0

はいおかげでたくさん、私は確認でき エンド –

+0

これはおそらくコードの一部であるif_navigational_formatですか?デヴィスの一部ではありません。 – rorra

+0

コードのうち、set_flash_messageがある場所では、通常、次のようなものを使用します。 flash [:notice] = I18n.t "devise.omniauth_callbacks.success"、:kind => "Linkedin"; sign_in(@user); redirect_to after_sign_in_path_for(@user) – rorra

関連する問題