deviseのuserに名前を足してみる

ついでに適当なバリデーションも入れてみる

diff --git a/app/models/user.rb b/app/models/user.rb
index 7d1ac58..04a015d 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -5,7 +5,9 @@
 class User < ActiveRecord::Base
          :recoverable, :rememberable, :trackable, :validatable
 
   # Setup accessible (or protected) attributes for your model
-  attr_accessible :email, :password, :password_confirmation
+  attr_accessible :email, :password, :password_confirmation, :name
+
+  validates_format_of :name, :with => /^[_a-zA-Z0-9]{3,24}$/
+  validates_uniqueness_of :name
 
   has_many :posts
 end
diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml
index a72712b..0c10633 100644
--- a/app/views/devise/registrations/new.html.haml
+++ b/app/views/devise/registrations/new.html.haml
@@ -1,6 +1,8 @@
 %h2 Sign up
 = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
   = devise_error_messages!
+  %p= f.label :name
+  %p= f.text_field :name
   %p= f.label :email
   %p= f.text_field :email
   %p= f.label :password
diff --git a/db/migrate/20100611063028_add_name_to_user.rb b/db/migrate/20100611063028_add_name_to_user.rb
new file mode 100644
index 0000000..fdd3b19
--- /dev/null
+++ b/db/migrate/20100611063028_add_name_to_user.rb
@@ -0,0 +1,9 @@
+class AddNameToUser < ActiveRecord::Migration
+  def self.up
+    add_column :users, :name, :string, :null => false, :default => ''
+    add_index :users, :name, :unique => true
+  end
+
+  def self.down
+    remove_column :users, :name
+  end
+end

user は極力いじらないで user_profile とかにわけたほうがいいのかなぁ?