Search code examples
ruby-on-railsdeviseomniauth

Devise with Omniauth for multiple models without STI


Is there any way to configure Devise Omniauth for multiple models without STI?

We have the models Students and Professors and we didn't want to use STI but now we realized that Devise with Omniauth doesn't play well with multiple models.

.rvm/gems/ruby-1.9.3-p125/gems/devise-2.1.0/lib/devise/rails/routes.rb:384:in `devise_omniauth_callback': Wrong OmniAuth configuration. If you are getting this exception, it means that either: (RuntimeError)

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

Solution

  • I think rather than writing :omniauthable to individual Student & Professor model. You should generate third model like Omniuser and add :omniauthable settings to it.

    class Student < ActiveRecord::Base
      has_one :omniuser
    end
    
    class Professor < ActiveRecord::Base
      has_one :omniuser
    end