I have two models
User(id, name, is_host,....)
Host(id, name, user_id,...)
With the Association
User hasOne Host
I am using Devise for the User Registration. When a user wants to register as a Host i want to set is_host = 1
and create a row in Host
with the name
of the Host he provides in the Registration Form.
What i want to do?
- Allow Registration Form to accept Host details
- Create the association data when user selects
register as host
Am trying to figure where i can write the logic based on what the user chooses to register as and then create the associated row in Host.
User From
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :first_name %><br />
<%= f.text_field :first_name, autofocus: true %>
</div>
<div class="field">
<%= f.label :last_name %><br />
<%= f.text_field :last_name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email %>
</div>
<div class="field">
<%= f.label :password %>
<% if @validatable %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<% f.label :password_confirmation %><br />
<% f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :is_host %><br />
<%= radio_button("user", "is_host", true) %> Yes
<br/>
<%= radio_button("user", "is_host", false) %> No
</div>
<div class="actions">
<%= f.submit "Signup" %>
</div>
<% end %>