[英]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.