Friday 15 February 2013

ruby on rails - Check two models during login with devise -


We are using Davis for authentication in railway app. We have two models- users and professionals. We have many professionals who are trying to enter in the form of accidental users, and would like to check to see if the registered user matches a professional if it fails for the user.

For example, to log in as a user, we want to display a flash message like this:

"We can not find username / password for this account. However, we got a business account, a professional. "

Any ideas on how to do this with Devise?

I did something similar with the functionality of the forgotten password. It can help you.

Edit : Added business check.

  Df reset @idiot = User.where (: email = & gt; parameter [: email]). Until first @ idiot.nil? Notifier. Send_reset_notice (@idiot). Deliver redirect_to new_user_session_url, notice: "#{@idiot.name}" will be emailed a new password. " Else @professional = Professional.where (: Email = & gt; Parameter [: Email]). Until first @ professional.nil? Redirect_to new_professional_session_url, notice: "That email address is assigned to the professional. Sign in below." Else redirect_to new_user_session_url ,: Flash = & gt; {: Error = & gt; "This email address matches any user." } End End   

and in this view:

    

You should take the right path.

No comments:

Post a Comment