Using Devise for two different models, but the same login form

I saw a lot of similar questions here, but nothing that fits my needs perfectly.

I'm a pretty experienced rails developer, but this new project is my first time using Rails 3 and Devise (I'm usually on authlogic).

There are two different models in my application that I want to authenticate through devise.

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

I want to be able to register both of them through one login form. Then, obviously, after they enter the system, they will be presented with different information depending on what type of model is included in the system.

It may or may not be relevant that I planned to use OmniAuth to allow users (though probably not businesses) to register / login via facebook.

Thanks!

What is the easiest way to do this?

+8
authentication ruby-on-rails ruby-on-rails-3 devise
source share
2 answers

I think that the only way to deal with this would be to have your own custom character in the form and controller that determines the type of user and then signs them correctly. I would recommend an approach similar to what is mentioned for simplicity (see how CanCan manage roles).

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

+5
source share

Can this be done in application_controller?

current_user = current_resource_a || current_resource_b

+2
source share

All Articles