Вопрос

I would like to make it possible for a User to select their "type" upon registration with devise. Do I need different registration forms for each "type" of User, or can I use one registration form?

Everything is pretty basic:

class User < ActiveRecord::Base
...
end

class Therapist < User
end

class Doctor < User
end

The form looks like this:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_na
me)) do |f| %>

<div><%= f.label :email %>
<%= f.email_field :email, :autofocus => true %></div>

<div><%= f.label :password %>
<%= f.password_field :password %></div>

<div><%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %></div>

<div><%= f.submit "Sign up" %></div>
<% end %>

Once the User completes this form, I was going to have them fill out another form specific to their User "type". Basically, my question is, what would the form_for tag look like to distinguish a user as a Therapist or Doctor?

Any help or guidance is greatly appreciated.

Это было полезно?

Решение

What if you ask the type in the signup form so that you could load your next form based on the type they specify here

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_na
    me)) do |f| %>

    <div><%= f.label :email %>
    <%= f.email_field :email, :autofocus => true %></div>

    <div><%= f.label :password %>
    <%= f.password_field :password %></div>

    <div><%= f.label :password_confirmation %>
    <%= f.password_field :password_confirmation %></div>


    <div><%= f.label :type %>
    <%= f.select :type, options_for_select(%w[User Therapist Doctor]) %></div>

    <div><%= f.submit "Sign up" %></div>
  <% end %>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top