Devise: 不使用email登錄

Devise用起來着實方便,按着教程很容易走下來,可是默認是用email登錄,若是改爲普通的username呢?html

  1. 安裝官方文檔完成安裝和設置git

    https://github.com/plataformatec/devise#getting-startedgithub

  2. 找到config/initializers/devise.rb中的下面內容,去掉註釋,將email改成usernamesession

    config.authentication_keys = [:email]app

  3. 生成devise的視圖文件ui

    rails generate devise:viewscode

  4. 把登錄和註冊的頁面中email改爲usernameorm

    app/views/devise/sessions/new.html.erb
    app/views/devise/registrations/new.html.erbhtm

  5. 以User爲模型做爲例子,去掉User類中的recoverable,再加上下面的代碼教程

    def email_required?
        false
    end
    
    def email_changed?
        false
    end

初步就是如此。

相關文章
相關標籤/搜索