简体   繁体   中英

How to migrate a custom User model to Devise in Rails 5.2

I'm new to Rails and have completed Michael Hartl's online tutorial and followed his steps to write the User model without using a gem as he recommended. I'd like to switch my user model/views etc... to Devise so that I can use some of its built-in features.

The problem is that I'm not sure if I should delete the codes before installing Devise gem or just add the gem onto of my code. I've searched online for a solution but a lot of the solution are outdated and haven't worked. Any help or link will be appreciated.

Devise will modify an existing model. So if your model is User just install Devise and then run

rails generate devise User

As described in the README. The main thing to be aware of is that Devise works best if the email field is the attribute email , if you've called it something like email_address I'd suggest you rename it before installing 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM