Using Devise for Two Different Models but the same Login Form?

I think the only way to handle this would be to have your own custom .

Up vote 2 down vote favorite 2 share g+ share fb share tw.

I have seen lots of similar questions here but nothing that quite fits my need. 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..) 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. 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.

Thanks! What's the easiest way to go about doing this? Ruby-on-rails ruby-on-rails-3 authentication devise link|improve this question asked Mar 25 '11 at 20:45johnnyPando9771925 96% accept rate.

Surely there would have to be a very good reason why you wouldn't have one user model, with different roles and a has_one relationship with the additional information available only to those with business role. – mark Mar 25 '11 at 21:07 I definitely thought about that, but it seemed like it would be making things more complicated than they had to be. Especially in regards to the Business signup form.

But that was my plan, provided there was no easy way to go about it in devise. – johnnyPando Mar 25 '11 at 21:18 With the business sign up you can easily nest the additional attributes into the registration form. Then define conditional validation depending on the type of sign up.

This in my opinion would be far easier than separating the models. – mark Mar 25 '11 at 21:41.

Ended up going with what mark suggested – johnnyPando Mar 29 '11 at 7:59.

Current_user = current_resource_a || current_resource_b.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions