UNLIMITED JAVA

WEB技術や普段の生活のブログ

How to use Devise and Rails , without EMail

Deviseでユーザ名だけで使うときに「Email can't be blank」とか言われちゃう場合の対処。


I thoght to use Devise only UserName.
But there are two problems.


1.It's called error message "Email can't be blank".
2.It's called error message "username can't be blank".


So, Modify the Model.rb as follows. (my model name is "Users")

class User < ActiveRecord::Base
.................

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me 
          ,:username

  # Email is not required
  def email_required?
    false
  end

end
  • Add -username to attr_accessible.
  • Override the method 'email_required?