# RESTful Authentication and dual login

**URL:** <https://www.ruby-forum.com/t/restful-authentication-and-dual-login/136618>\
**Category:** Rails\
**Created:** [May 4, 2008, 4:06pm UTC](https://www.ruby-forum.com/t/restful-authentication-and-dual-login/136618 "2008-05-04T16:06:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Costo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f4b2a3/32.png) [@Costo](https://www.ruby-forum.com/u/Costo)\
**Post date:** [May 4, 2008, 4:06pm UTC](https://www.ruby-forum.com/t/restful-authentication-and-dual-login/136618/1 "2008-05-04T16:06:10Z")

</div>

Hello all,

I’m setting up a RIA with 2 separate “sub sites” (with namespaces in  
the routes), let’s say one for the clients, the other for the  
dealers.  
I want to use RESTful authentication, have followed the nice tutorial  
available here ([http://railsforum.com/viewtopic.php?id=14216&p=1](http://railsforum.com/viewtopic.php?id=14216&p=1)) and  
it works perfectly, but it is not adapted to my dual login system, and  
I’m really scratching my head to modify this. I come from a C++/PHP  
background, so I’m still finding my marks around models, filters, REST  
routes (ressources), etc.

So should I keep :

- one “users” model, with 2 :has\_one relationships (1 to clients  
model, 1 to dealers model, of course mutually exclusive) and a boolean  
in the users model to indicate if it’s a client or a dealer ;
- or no users model but two totally separate and complete models  
(“clients” and “dealers”), with all user information in each, and only  
1 stored in the session, but then how could I know which one ? and  
that means no more current\_user in the session but rather a  
current\_client OR current\_dealer ?

Help, I’m really stuck on that one, I can’t decide the most natural  
(and most DRY) method of applying my “simple” business rule in a rails  
2.0 environment.

Laurent Cortier.

---

<div class="post-metadata">

**Author:** ![Costo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f4b2a3/32.png) [@Costo](https://www.ruby-forum.com/u/Costo)\
**Post date:** [May 6, 2008, 12:49am UTC](https://www.ruby-forum.com/t/restful-authentication-and-dual-login/136618/2 "2008-05-06T00:49:45Z")

</div>

> My gut instinct is it’d be easier to have one user table.

Yes, I’m studying the STI way for now, even if only to add specialized  
foreign keys to actual user data.  
The problem here is that my gut instinct doesn’t work like it should  
because Rails re-defines web programming following many design  
patterns still not clearly assimilated by my own CPU 😛

---

<div class="post-metadata">

**Author:** ![Costo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f4b2a3/32.png) [@Costo](https://www.ruby-forum.com/u/Costo)\
**Post date:** [May 5, 2008, 6:48am UTC](https://www.ruby-forum.com/t/restful-authentication-and-dual-login/136618/3 "2008-05-05T06:48:38Z")

</div>

My gut instinct is it’d be easier to have one user table.  
-R
