2014-07-04 6 views
5

संस्करणों का संस्करण मेरे पास एक मॉडल उम्मीदवार है जो सर्वव्यापी (लिंकिन) तैयार करता है।डेविस + Omniauth,

अब तक, मेरी routes.rb इस तरह देखा:

namespace :v1 do 
    devise_for :candidates, only: :omniauth_callbacks 
    ... 
end 

सब कुछ अच्छी तरह से काम जब तक मैं एक नया संस्करण जोड़ने के लिए किया था:

namespace :v2 do 
    devise_for :candidates, only: :omniauth_callbacks 
    ... 
end 

namespace :v1 do 
    devise_for :candidates, only: :omniauth_callbacks 
    ... 
end 

वर्तमान विन्यास के साथ, मैं मिलता है यह त्रुटि:

`set_omniauth_path_prefix!': Wrong OmniAuth configuration. If you are getting this exception, it means that either: (RuntimeError) 
1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one 
2) You are setting :omniauthable in more than one model 
3) You changed your Devise routes/OmniAuth setting and haven't restarted your server 

यह बहुत परेशान पाप है सीई मैं उम्मीदवार को दोनों संस्करणों पर प्रमाणीकृत करने में सक्षम होना चाहता हूं।

मैं क्या कर सकता हूं?

+1

क्या आपको कोई समाधान मिला? मुझे यहां ठीक उसी समस्या का सामना करना पड़ रहा है। :( – jlstr

+0

मैंने नहीं किया, अगर आपको कुछ मिल जाए तो मुझे बताएं;) –

+1

हाँ !, मुझे यह पता चला कि इसे कैसे ठीक किया जाए। मैं इसे जल्द ही एक उत्तर के रूप में पोस्ट करूंगा। – jlstr

उत्तर

12

ठीक है, चलो एक छोटा सा यहाँ सारांश यह है, वसीयत आप एक scope अंदरdevise_for विधि या एक namespace मार्ग config/routes.rb फाइल में परिभाषित है, है ना कॉल करने की अनुमति नहीं है?

मेरे namespace'd मार्ग इस तरह दिखता है:

namespace :api, constraints: { format: :json } do 
    devise_for :users, skip: [ :registrations, :passwords, :confirmations ] 
    resources :profiles, only: :show 
end 

और यह काम करता है!

मैंने इसे काम करने के लिए क्या किया? जवाब config/initializers/devise.rb फ़ाइल में निहित है। फ़ाइल यह कहता है के तल के पास बाहर की जाँच करें ...

# When using omniauth, Devise cannot automatically set Omniauth path, # so you need to do it manually. For the users scope, it would be:

अगले टिप्पणी की लाइन आपको एक उदाहरण, कि लाइन टिप्पणी हटाएं पता चलता है और अपनी आवश्यकताओं के अनुसार यह संशोधित करने, मेरे मामले के लिए (यानी मेरे ऊपर नामित मार्ग के लिए) मेरे पास है:

config.omniauth_path_prefix = "/api/users/auth" 

और यही वह है! .... मैंने ऐसा किया और यह सब पूरी तरह से काम करना शुरू कर दिया!

उम्मीद है कि यह मदद करता है!

+1

धन्यवाद यह वास्तव में सहायक है –