按照以下鏈接正確提到的所有步驟:
https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users
修改用戶模型
首先,添加設計:confirmable
您models/user.rb
文件
創建一個新的遷移
然後,執行遷移:
rails g migration add_confirmable_to_devise
將生成db/migrate/YYYYMMDDxxx_add_confirmable_to_devise.rb.
將以下內容添加到它以執行遷移。
class AddConfirmableToDevise < ActiveRecord::Migration
# Note: You can't use change, as User.update_all will fail in the down migration
def up
add_column :users, :confirmation_token, :string
add_column :users, :confirmed_at, :datetime
add_column :users, :confirmation_sent_at, :datetime
# add_column :users, :unconfirmed_email, :string # Only if using reconfirmable
add_index :users, :confirmation_token, unique: true
# User.reset_column_information # Need for some types of updates, but not for update_all.
# To avoid a short time window between running the migration and updating all existing
# users as confirmed, do the following
execute("UPDATE users SET confirmed_at = NOW()")
# All existing user accounts should be able to log in after this.
# Remind: Rails using SQLite as default. And SQLite has no such function :NOW.
# Use :date('now') instead of :NOW when using SQLite.
# => execute("UPDATE users SET confirmed_at = date('now')")
# Or => User.all.update_all confirmed_at: Time.now
end
def down
remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at
# remove_columns :users, :unconfirmed_email # Only if using reconfirmable
end
end
您還可以生成相應的設計意見,如果他們尚未建立:
rails generate devise:views users
進行遷移rake db:migrate
重新啓動服務器。
這是正確的行爲。確認/新建用於重新發送確認郵件,並且在註冊後您不需要該頁面,因爲註冊過程本身會發送確認電子郵件。只有當用戶點擊「重新發送確認電子郵件」鏈接時才應該訪問該新頁面。 – Sajan
嗨@Sajan - 這是正確的行爲? 它永遠不會告訴用戶電子郵件需要確認。它只是重定向登錄,並帶有警報 - 「您需要登錄...」 –