Reputation: 54949
I have two types of registration on on my website.
There are two models related to Registration
users(id, name, is_host, ...)
hosts(company_name, user_id, status, ...)
Every Host is a User by default on the application. When the User signups on the website he has to enter the following fields
When a Host Signups he has to enter the following
On submitting the form as a host it should save the data in the User model and also set the is_host
flag to 1
which other wise is 0
and then store the company_name
in the hosts
model.
What i have done?
I have installed devise and generated the migration tables and generated the scoped views.
What i am trying to achieve?
strong parameter
for the User sign up form?HOSTS
views/users/registrations/new.html.erb
<h2>Sign up!!</h2>
<%= 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="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "users/shared/links" %>
Server Error:
Unpermitted parameters: first_name, last_name
Upvotes: 3
Views: 1441
Reputation: 669
Please look this example....
class AddFieldsToUsers < ActiveRecord::Migration
def change
add_column :users, :first_name, :string
add_column :users, :last_name, :string
end
end
h2 Sign up
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= devise_error_messages!
div
= f.label :first_name
br
= f.text_field :first_name, autofocus: true
div
= f.label :last_name
br
= f.text_field :last_name
div
= f.label :email
br
= f.email_field :email
div
= f.label :password
br
= f.password_field :password
div
= f.label :password_confirmation
br
= f.password_field :password_confirmation
div
= f.submit 'Sign up'
= render 'devise/shared/links'
def sign_up_params
devise_parameter_sanitizer.sanitize(:sign_up)
end
def account_update_params
devise_parameter_sanitizer.sanitize(:account_update)
end
class RegistrationsController < Devise::RegistrationsController
private
def sign_up_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
end
def account_update_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password)
end
end
devise_for :users, :controllers => { registrations: 'registrations' }
Upvotes: 3