简体   繁体   中英

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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