[英]Omniauth “with” STI and devise
I'm figured out with no results. 我觉得没有结果。 I have a model named User and to models with STI fan and artist, like this:
我有一个名为User的模型和带有STI粉丝和艺术家的模型,如下所示:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :confirmable, :lockable,
:recoverable, :rememberable, :trackable, :validatable, **:omniauthable**
end
and my others models 和我的其他模特
Class Artist < User end
Class Fan < User end
my routes 我的路线
devise_for :users
devise_for :artists
devise_for :fans
I have a problem when try to run my server or anything else i got this error 尝试运行我的服务器或其他任何我遇到此错误时遇到问题
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
my app is advanced and don't wanna go back and refactor it, any help will appreciate 我的应用程序是先进的,不想回去重构它,任何帮助将不胜感激
The answer can be found here . 答案可以在这里找到。
Devise gets mixed up since you are calling devise_for
for three different models and one of them is using the omniauthable
module. 由于您为三个不同的模型调用
devise_for
,其中一个使用omniauthable
模块,因此Devise变得混乱。
Either: 或者:
Remove all devise_for
methods except for :users
. 删除除以下
:users
之外的所有devise_for
方法。
Or remove the omniauthable
module from the user model, create your own omniauth routes and stop using devise's middleware by moving your omniauth configuration into a new file. 或者从用户模型中删除
omniauthable
模块,创建自己的omniauth路由,并通过将omniauth配置移动到新文件中来停止使用devise的中间件。 So, instead of having this in devise.rb
: 所以,而不是在
devise.rb
中有这个:
Devise.setup do |config| config.omniauth :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] end
You now have this in your new file omniauth.rb
: 您现在在新文件
omniauth.rb
有此:
Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] end
The Railscast on Simple OmniAuth should help you setting this up. Simple OmniAuth上的Railscast应该可以帮助您进行设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.