设计与Omniauth为多个型号没有STI [英] Devise with Omniauth for multiple models without STI

查看:119
本文介绍了设计与Omniauth为多个型号没有STI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们有模型学生和教授,我们不想使用STI,但现在我们意识到,使用Omniauth的Devise与多种型号不兼容。

  .rvm / gems / ruby​​-1.9.3- p125 / gems / devise-2.1.0 / lib / devise / rails / routes.rb:384:在`devise_omniauth_callback'中:错误的OmniAuth配置。如果你得到这个异常,这意味着:(RuntimeError)

1)你手动设置OmniAuth.config.path_prefix,它不匹配Devise一个
2)你正在设置:在多个模型中的全方位
3)您更改了设计路线/ OmniAuth设置,并且没有重新启动服务器


解决方案

我认为,而不是将:omniauthable 写入个人学生& 教授模型。您应该生成第三个模型,如 Omniuser ,并向其添加:omniauthable 设置。

  class Student< ActiveRecord :: Base 
has_one:omniuser
end

class Professor< ActiveRecord :: Base
has_one:omniuser
end


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

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆