如何使用 Rails 上的 Ruby Devise 库为两个模型提供两个不同的模板

How to give two different templates for two models using Ruby on Rails Devise library

我是 Rails 上的 Ruby 的新手,在使用设计库时遇到问题。我有两个带有设计库的模型,它们需要有不同的注册字段。

目前默认模板位于文件夹中 app/app/views/devise/registrations/.

但可能我想要 app/app/views/devise/registrations/model1/registration_template.rb、app/app/views/devise/registrations/model2/registration_template.rb

现在我不确定这是在哪里处理的。只要我可以为两个模型使用两个不同的模板并将应用程序定向到每个模型的正确模板,它们甚至不必存在于单独的文件夹中。

来自 Devise 的自述文件:

If you have more than one Devise model in your application (such as User and Admin), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set config.scoped_views = true inside the config/initializers/devise.rb file.

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. You can also use the generator to generate scoped views:

rails generate devise:views users

希望对您有所帮助