使用设计为两种不同的模式,但同样的登录表单 [英] Using Devise for Two Different Models but the same Login Form

查看:121
本文介绍了使用设计为两种不同的模式,但同样的登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了很多在这里类似的问题,但没有什么很适合我的需要。

I have seen lots of similar questions here but nothing that quite fits my need.

我是pretty经验Rails开发者,但这个新项目是我第一次同时使用Rails 3中,并制定(我通常是在authlogic)。

I am a pretty experience rails developer but this new project is my first time using both Rails 3 and Devise (I'm normally on authlogic).

我的应用程序有,我想通过设计一种身份验证两种不同的模式。

My app has two different models that I want to authenticate via devise.

一,用户仅仅是一个标准用户模式
二,业务类似于一个用户,(它有一个电子邮件地址栏也是如此),但它在数据库的其他信息(地址,电话号码等)

One, User is just a standard users model Two, Business is similar to a user, (it has an email address column too) but it has additional info in the database (address, phone number, etc..)

我希望能够通过相同的登录表单登录他们俩英寸那么很明显,一旦被记录在他们会用不同的方式取决于已登录什么类型的模型psented $ P $。

I want to be able to log them both in via the same login form. Then obviously once they are logged in they will be presented with different info depending on what type of Model has logged in.

它可能或可能不相关,我是打算使用OmniAuth允许用户(虽然可能不是企业),以通过Facebook注册/上。

It may or may not be relevant that I was planning on using OmniAuth to allow Users (though probably not businesses) to sign up/on via facebook.

谢谢!

什么是去这样做最简单的方法?

What's the easiest way to go about doing this?

推荐答案

我觉得处理这将是在形式和控制器,确定用户的类型自己的自定义符号,然后正确地签下他们的唯一途径。我建议像简单提到什么标记的方法(来看看像惨惨管理角色) 。

I think the only way to handle this would be to have your own custom sign in form and controller that determined the type of user and then sign them in correctly. I would recommend an approach like what mark mentioned for simplicity (take a look at something like CanCan to manage roles).

具有多用户模型的另一个潜在问题是,你将拥有所有的色器件的辅助方法多个版本。因此,对于 CURRENT_<资源> <资源> _signed_in 你会 CURRENT_USER current_business_user user_signed_in? business_user_signed_in?。然后,你要么必须实现自己的这些方法版本,或者你需要到处检查两个版本你使用它们。

Another potential problem with having multiple user models is that you will have multiple versions of all the devise helper methods. So for current_<resource> and <resource>_signed_in? you would have current_user, current_business_user, user_signed_in? and business_user_signed_in?. Then you would either have to implement your own versions of these methods or you would need to check both versions everywhere you used them.

这篇关于使用设计为两种不同的模式,但同样的登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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