I am implementing devise for user registration but some customizations and it is below.
I searched a lot on internet but could not find answer.
Problem: I do not know how to create secret code in rails and then send it to user thourgh email and then match it with code that user got.
Note: Secret code and password are two different things in my application.
Devise has an internal module called Confirmable
that does exactly this.
In order to use it, all you need to do is:
Make sure your devise model is :confirmable
and :registerable
class User # ... devise :confirmable, :registerable ... # ... end
Run a migration that creates confirmation_token fields
class AddConfirmableToUsers < ActiveRecord::Migration def self.up change_table(:users) do |t| t.confirmable end add_index :users, :confirmation_token, :unique => true end def self.down remove_column :users, :confirmable end end
If you already have users, and don't want them to follow this confirmation process, than you need to make them confirmed. You can do that doing
User.update_all ["confirmed_at = ?", Time.now]
on the console.
More references: Confirable Module , Adding confirmable to Users in Devise
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.