[英]Omniauth “with” STI and devise
我覺得沒有結果。 我有一個名為User的模型和帶有STI粉絲和藝術家的模型,如下所示:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :confirmable, :lockable,
:recoverable, :rememberable, :trackable, :validatable, **:omniauthable**
end
和我的其他模特
Class Artist < User end
Class Fan < User end
我的路線
devise_for :users
devise_for :artists
devise_for :fans
嘗試運行我的服務器或其他任何我遇到此錯誤時遇到問題
Wrong OmniAuth configuration. If you are getting this exception, it means that either:
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
我的應用程序是先進的,不想回去重構它,任何幫助將不勝感激
答案可以在這里找到。
由於您為三個不同的模型調用devise_for
,其中一個使用omniauthable
模塊,因此Devise變得混亂。
或者:
刪除除以下:users
之外的所有devise_for
方法。
或者從用戶模型中刪除omniauthable
模塊,創建自己的omniauth路由,並通過將omniauth配置移動到新文件中來停止使用devise的中間件。 所以,而不是在devise.rb
中有這個:
Devise.setup do |config| config.omniauth :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] end
您現在在新文件omniauth.rb
有此:
Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] end
Simple OmniAuth上的Railscast應該可以幫助您進行設置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.