devise for two models

2019-05-11 13:56发布

问题:

I am building an app with "nested authentication" That means that I have a House modle (with devise) and a house has many users and once inside the House authentication, I would like the users to be able to sign in as well. I have also added a User model with Devise. My question is that right now I am getting errors because I the devise sign_up form that I have designed for Houses doesn't work for the User model. How do I create separate sign_up and sign_in forms for two different user models with devise? Or is there a better way to go about doing this? Thanks!

回答1:

How do I create separate sign_up and sign_in forms for two different user models with devise?

rails g devise:views

This will create an app/views/devise.

Then: set "config.scoped_views = true" inside "config/initializers/devise.rb".

From the README:

After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will use the default view at "devise/sessions/new".