繁体   English   中英

Omniauth“与”STI和设计

[英]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变得混乱。

或者:

  1. 删除除以下:users之外的所有devise_for方法。

  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 

    Simple OmniAuth上的Railscast应该可以帮助您进行设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM