Omniauth“与” STI和设计 [英] Omniauth "with" STI and devise

查看:114
本文介绍了Omniauth“与” STI和设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没想到没有结果。我有一个名为User的模型,以及STI风扇和艺术家的模型,如下所示:

  class User< ActiveRecord :: Base 
devise:database_authenticatable,:可注册,:可确认,可锁定,
:可恢复,可记忆,可追溯,可验证**:omniauthable **
end

和我的其他型号

 code> Class Artist<用户端
类风扇<用户结束

我的路线

  devise_for:users 
devise_for:artists
devise_for:fans

我有一个问题,当尝试运行我的服务器或任何其他我有这个错误

 错误的OmniAuth配置。如果你得到这个例外,这意味着:

1)你手动设置OmniAuth.config.path_prefix,它不匹配Devise一个
2)你正在设置:在多个模型中可以使用
3)您更改了设计路线/ OmniAuth设置,并且没有重新启动服务器

我的应用程序是高级的,不想退回并重构,任何帮助将会欣赏

解决方案

答案可以在 here 找到。



由于您为三种不同的型号调用 devise_for ,其中一个使用 omniauthable module。



任一:


  1. 全部删除 devise_for 之外的方法:用户


  2. 或从中删除 omniauthable 模块用户模型,创建自己的全方位路线,并通过将您的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

    简易OmniAuth上的Railscast应该可以帮助您设置。



I'm figured out with no results. I have a model named User and to models with STI fan and artist, like this:

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.

Either:

  1. Remove all devise_for methods except for :users.

  2. 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. So, instead of having this in 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:

    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.

这篇关于Omniauth“与” STI和设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆