使用 Omniauth 为没有 STI 的多个模型设计 [英] Devise with Omniauth for multiple models without STI
本文介绍了使用 Omniauth 为没有 STI 的多个模型设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在没有 STI 的情况下为多个模型配置 Devise Omniauth?
Is there any way to configure Devise Omniauth for multiple models without STI?
我们有模型学生和教授,我们不想使用 STI,但现在我们意识到设计与 Omniauth 不能很好地处理多个模型.
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
推荐答案
我认为与其将 :omniauthable
写给单个 Student
&教授模式
.您应该生成第三个模型,如 Omniuser
并向其添加 :omniauthable
设置.
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
这篇关于使用 Omniauth 为没有 STI 的多个模型设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文