【问题标题】:Omniauth "with" STI and deviseOmniauth “与” STI 并设计
【发布时间】:2012-11-26 14:42:08
【问题描述】:

我发现没有结果。我有一个名为 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

我的应用程序很先进,不想回去重构它,任何帮助将不胜感激

【问题讨论】:

    标签: ruby-on-rails devise omniauth


    【解决方案1】:

    答案可以在here找到。

    Devise 搞混了,因为您为三个不同的模型调用 devise_for,其中一个使用了 omniauthable 模块。

    要么:

    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
      

      The Railscast on Simple OmniAuth 应该可以帮助您进行设置。

    【讨论】:

    • 我无法在所有三个模型上进行单点登录。设计默认为一个模型,就是这样。我自己使用 Omniauth 并删除了 :omniauthable
    • 你试过什么?我已经用 Railscast 的链接更新了我的答案,应该会有所帮助。
    猜你喜欢
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    相关资源
    最近更新 更多