2012-11-26 63 views
1

我想通了沒有結果。我有一個型號命名用戶,並與STI風扇和藝術家,這樣的機型:Omniauth「與」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 

我的應用程序是先進的,不想回去重構它,任何幫助將升值

回答

4

答案可以找到here

由於您正在爲三種不同型號調用devise_for,因此設計變得混亂起來,其中一個模塊正在使用omniauthable模塊。

或者:

  1. 刪除所有devise_for方法除了:users

  2. 或者從用戶模型中刪除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 
    

    The Railscast on Simple OmniAuth應該可以幫助您設置此功能。

+0

太好了我現在在正確的方式,謝謝! – BlackSan

+0

我在爲所有三種模型獲取單點登錄方面遇到問題。設計默認爲一個模型,就是這樣。我自己使用Omniauth,並已刪除:omniuthable – Dex

+0

你有什麼試過?我已經更新了我的答案,並提供了一個應該有所幫助的Railscast鏈接。 – Ashitaka