Topic: creating an account with a username in devise

Hello, all.  I have followed these links and have enabled a (current) user to login with a username:

railscasts 209, introducting devise
railscasts 210, customing devise
github plataformatec devise, how to allow users to sign in using their username or email

I want to allow a user to sign up with a username but am getting these errors and don't know how to proceed.  Notice the 'Email can't be blank' error, even though I'm not wanting to accept an email for authentication.  It also doesn't recognize that I entered a password or that they matched (even though they did):

Sign up
3 errors prohibited this user from being saved:
Email can't be blank
Password can't be blank
Password confirmation doesn't match Password

I've edited the devise view to prompt for a first and last name instead of a username:


<h3>Sign up</h3>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>
  <div><%= f.label :firstname, "First Name", :autofocus => true %><br />
  <script type="text/javascript">window.onload = function() {document.getElementById('user_firstname').focus();}</script>
  <%= f.text_field :firstname %></div>

  <div><%= f.label :lastname, "Last Name", :autofocus => true %><br />
  <%= f.text_field :lastname %></div>

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

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

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

<%= render :partial => "devise/shared/links" %>

and I've edited my model to generate a username from the first and last name:


class User < 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 => [:username]

  # Setup accessible (or protected) attributes for your model
  #attr_accessor :username
  validates_presence_of :firstname, :lastname, :unique => 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
    username=lastnamePart + firstnamePart
    while username.length != 7
      username=username + count.to_s
      count +=1
    #verify username uniqueness, how?

  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 => login.downcase }]).first

Please let me know if you require any further information.  Any help would be greatly appreciated.  Thanks.