问题
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
回答1:
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:
Remove all
devise_for
methods except for:users
.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 indevise.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.
来源:https://stackoverflow.com/questions/13567113/omniauth-with-sti-and-devise