title: Rails - How to add a column to devise custom field in the right way?
body: <p>I want to add a user's custom field such as name, sex and description to the devise gem on Rails.</p>
  
  <p>I put there code to my application_controller:</p>
  
  <pre><code>before_action :configure_devise_permitted_parameters, if: :devise_controller?
  
  protected
  def configure_devise_permitted_parameters
    registration_params = [:name, :sex, :description, :email, :password, :password_confirmation]
  
    if params[:action] == 'update'
      devise_parameter_sanitizer.for(:account_update) { 
        |u| u.permit(registration_params &lt;&lt; :current_password)
      }
    elsif params[:action] == 'create'
      devise_parameter_sanitizer.for(:sign_up) { 
        |u| u.permit(registration_params) 
      }
    end
  end
  </code></pre>
  
  <p>and generated a migration to add these fields to the users table:</p>
  
  <pre><code>class AddNameSexDescriptionToUsers &lt; ActiveRecord::Migration
    def change
      add_column :users, :name, :string
      add_column :users, :sex, :integer
      add_column :users, :description, :text
    end
  end
  </code></pre>
  
  <p>Here I set the sex column to integer, but I want to show string on the view page like Male, Female, Unknown.</p>
  
  <p>I want to show the list in a dropdown list box. </p>
  
  <p>Here I changed the devise's <code>registrations/edit.html.erb</code> source:</p>
  
  <pre><code>&lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name), :html =&gt; { :method =&gt; :put }) do |f| %&gt;
  &lt;!-- etc. --&gt;
  &lt;div class="form-group"&gt;
    &lt;%= f.label :sex %&gt;&lt;br /&gt;
    &lt;%= f.select :sex, ?, class: "form-control" %&gt;
  &lt;/div&gt;
  &lt;!-- etc. --&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>If I create a sex model, I can set the <code>f.select</code> like this:</p>
  
  <pre><code>&lt;%= f.select :sex, Sex.all.map{|t| [t.name, t.id]}, class: "form-control" %&gt;
  </code></pre>
  
  <p>But I think it is unnecessary to make a table only save three records. Then how to do it in a good way for the sex?</p>