title: Creating an account with a username
body: <p>I have followed the <a href="https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-sign-in-using-their-username-or-email-address/%22devise%20wiki%22" rel="nofollow">devise wiki</a> to enable username login with devise (instead of email).  But I can't figure out how to enable username signup/registration with devise.</p>
  
  <p>I have changed my registration view to prompt for a first and last name and a password.</p>
  
  <p>app/views/devise/registrations/new.html.erb:</p>
  
  <pre><code>&lt;h3&gt;Sign up&lt;/h3&gt;
  
  &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt;
    &lt;%= devise_error_messages! %&gt;
    &lt;div&gt;&lt;%= f.label :firstname, "First Name", :autofocus =&gt; true %&gt;&lt;br /&gt;
    &lt;script type="text/javascript"&gt;window.onload = function() {document.getElementById('user_firstname').focus();}&lt;/script&gt;
    &lt;%= f.text_field :firstname %&gt;&lt;/div&gt;
  
    &lt;div&gt;&lt;%= f.label :lastname, "Last Name", :autofocus =&gt; true %&gt;&lt;br /&gt;
    &lt;%= f.text_field :lastname %&gt;&lt;/div&gt;
  
    &lt;div&gt;&lt;%= f.label :password %&gt;&lt;br /&gt;
    &lt;%= f.password_field :password %&gt;&lt;/div&gt;
  
    &lt;div&gt;&lt;%= f.label :password_confirmation %&gt;&lt;br /&gt;
    &lt;%= f.password_field :password_confirmation %&gt;&lt;/div&gt;
  
    &lt;div&gt;&lt;%= f.submit "Sign up" %&gt;&lt;/div&gt;
  &lt;% end %&gt;
  
  &lt;%= render :partial =&gt; "devise/shared/links" %&gt;
  </code></pre>
  
  <p>I've edited my model to generate a username from the first and last name:</p>
  
  <p>app/models/user.rb</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :authentication_keys =&gt; [:username]
  
    # Setup accessible (or protected) attributes for your model
    #attr_accessor :username
    validates_presence_of :firstname, :lastname, :unique =&gt; true 
    after_validation :createUsername
    attr_accessible :username, :password, :password_confirmation, :remember_me, :firstname, :lastname
    #attr_protected :password
  
    def createUsername
      # create username from first-last name
      firstnamePart=self.firstname[0,1].downcase
      lastnamePart=self.lastname[0,5].downcase
      username=lastnamePart + firstnamePart
      count=0
      while username.length != 7
        username=username + count.to_s
        count +=1
      end
      self.username=username
      #verify username uniqueness?
    end
  
  
    def self.find_first_by_auth_conditions(warden_conditions)
        conditions = warden_conditions.dup
        if login = conditions.delete(:login)
          where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value =&gt; login.downcase }]).first
        else
          where(conditions).first
        end
      end
  end
  </code></pre>
  
  <p>But when I try to sign up I get the following error.  Text will have to do because I don't have enough 'reputation' to post images:</p>
  
  <pre><code>Sign up
  1 error prohibited this user from being saved:
  Email can't be blank
  </code></pre>
  
  <p>so, devise is still looking for an email during the signup/registration phase.  I assume I have to edit devise's controller but that didn't get installed in the following commands</p>
  
  <ol>
  <li>rails g devise:install</li>
  <li>rails g devise user</li>
  <li>rails g devise:views</li>
  </ol>
  
  <p>So my rails app is probably using a default devise controller (/usr/local/rvm/gems/ruby-2.0.0-p195/gems/devise-1.5.4/app/controllers/devise/registrations_controller.rb) but I didn't see any references to 'email' in there.</p>
  
  <p>How do I change devise to accept a username during signup/registration?  Any help would greatly be appreciated.</p>