设计,Omniauth和STI的多种型号 [英] Devise, Omniauth and multiple models with STI

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

问题描述

我有一个使用sti(基本用户模型和另外两个模型 - 公司和个人 - 继承自己)的设计认证的应用程序设置。从设计的角度来看,一切正在发生。我可以有不同的注册表单路线,一切都按预期工作。现在我想给两个用户(公司和个人)使用Facebook或链接注册/登录的选项。如果我在两个模型上设置:omniauthable,并在每个模型的我的routes.rb上设置devise_for,我得到一个错误说,只有一个模型可以全方位的。如果我不为每个模型使用devise_for,则不会生成路由。如果我仅在用户模型上设置了全方位,我只能得到一条路线和一个回调。



我已经在某处找到解决方案是自己使用omniauth (与设计分开)。然而,我似乎无法使用与设计不同的omniauth来实现预期的行为(我可以得到一个单一的授权/回调路由,而是两个,如预期)。





TIA

解决方案

Devise的Omniauthable模块支持多种型号。请参阅



https ://github.com/plataformatec/devise/wiki/OmniAuth-with-multiple-models


I have an application setup with devise authentication using sti (base user model and two other models - company and individual - inheriting from it). From a devise perspective, everything is working. I can have different routes for signup forms and everything works as expected. Now I wanted to give both users (company and individual) the option to signup/sign in using facebook or linked in. If I set the :omniauthable on both models, and set the devise_for on my routes.rb for each model, I get an error saying that only one model can be omniauthable. If I don't use the devise_for for each model, no routes are generated. If I set the omniauthable on user model only, I get only one route and one callback.

I've read somewhere that the solution would be to use omniauth on its own (separated from devise). However, I can't seem to achieve the intended behavior using omniauth separate from devise (I can get one single authorize/callback route, but the two, as intended).

Anyone out there who can help ?

TIA

解决方案

Devise's Omniauthable module does support multiple models. See

https://github.com/plataformatec/devise/wiki/OmniAuth-with-multiple-models

这篇关于设计,Omniauth和STI的多种型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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