我知道有噸教程已經解釋如何做到這一點的,但我已經花了太多時間試圖使其無功而返工作...Rails 3 + Devise 1.3.4:如何使用用戶名登錄?
在他們解釋瞭如何使用用戶名或電子郵件登錄的官方文檔。我只想使用用戶名登錄。
我所做的:
1. rails generate migration add_username_to_users username:string
2. rake db:migrate
3. rails generate devise:views
我的應用程序/模型/ user.rb:(我只加:在attr_accessible用戶名)
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
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
end
我的配置/初始化/ devise.rb :
...
config.authentication_keys = [ :username ]
...
我的應用程序/視圖/設計/會話/ new.html.erb:
...
<p><%= f.label :username %><br />
<%= f.text_field :username %></p>
...
我相信這是一切都有改變,但它只會說「無效的電子郵件或密碼」。
謝謝你的幫助..!
雖然它並沒有解決你的問題。 「無效的電子郵件或密碼」消息位於config/local/en.yml用戶設備:失敗:無效 如果您將其更改爲驗證用戶名,則應更改該設置。 – Olives 2011-06-17 18:15:15